Mercurial > vim
annotate src/buffer.c @ 18203:e0ec4cd7a865 v8.1.2096
patch 8.1.2096: too many #ifdefs
Commit: https://github.com/vim/vim/commit/8c96af9c05bfcac2d5ae081e098d4863db561511
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 28 19:05:57 2019 +0200
patch 8.1.2096: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_COMMENTS.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 28 Sep 2019 19:15:03 +0200 |
parents | c81370b3ede4 |
children | 6c3a8312486d |
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 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
55 #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
|
56 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
|
57 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
|
58 #endif |
3365 | 59 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
|
60 |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
61 // 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
|
62 static int buf_free_count = 0; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
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 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
|
65 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
|
66 |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
67 /* |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
68 * 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
|
69 */ |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
70 int |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
71 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
|
72 { |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
73 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
|
74 } |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
75 |
16996
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
76 /* |
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
77 * 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
|
78 */ |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
79 static int |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
80 read_buffer( |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
81 int read_stdin, /* read file from stdin, otherwise fifo */ |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
82 exarg_T *eap, /* for forced 'ff' and 'fenc' or NULL */ |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
83 int flags) /* extra flags for readfile() */ |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
84 { |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
85 int retval = OK; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
86 linenr_T line_count; |
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 /* |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
89 * 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
|
90 * 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
|
91 * 'fileencoding' was guessed wrong. |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
92 */ |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
93 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
|
94 retval = readfile( |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
95 read_stdin ? NULL : curbuf->b_ffname, |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
96 read_stdin ? NULL : curbuf->b_fname, |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
97 (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
|
98 flags | READ_BUFFER); |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
99 if (retval == OK) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
100 { |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
101 /* Delete the binary lines. */ |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
102 while (--line_count >= 0) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
103 ml_delete((linenr_T)1, FALSE); |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
104 } |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
105 else |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
106 { |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
107 /* Delete the converted lines. */ |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
108 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
|
109 ml_delete(line_count, FALSE); |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
110 } |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
111 /* Put the cursor on the first line. */ |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
112 curwin->w_cursor.lnum = 1; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
113 curwin->w_cursor.col = 0; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
114 |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
115 if (read_stdin) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
116 { |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
117 /* Set or reset 'modified' before executing autocommands, so that |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
118 * 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
|
119 if (!readonlymode && !BUFEMPTY()) |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
120 changed(); |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
121 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
|
122 unchanged(curbuf, FALSE, TRUE); |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
123 |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
124 if (retval == OK) |
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
125 { |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
126 #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
|
127 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
|
128 curbuf, &retval); |
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
129 #else |
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(EVENT_STDINREADPOST, NULL, NULL, FALSE, curbuf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
131 #endif |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
132 } |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
133 } |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
134 return retval; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
135 } |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
136 |
7 | 137 /* |
17225
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
138 * 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
|
139 */ |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
140 void |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
141 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
|
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 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
|
144 { |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
145 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
|
146 |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 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
|
151 } |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
152 } |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
153 |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
154 /* |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
155 * 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
|
156 * memory. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
157 * Return FAIL for failure, OK otherwise. |
7 | 158 */ |
159 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
160 open_buffer( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
161 int read_stdin, /* read file from stdin */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
162 exarg_T *eap, /* for forced 'ff' and 'fenc' or NULL */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
163 int flags) /* extra flags for readfile() */ |
7 | 164 { |
165 int retval = OK; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
166 bufref_T old_curbuf; |
4139 | 167 #ifdef FEAT_SYN_HL |
168 long old_tw = curbuf->b_p_tw; | |
169 #endif | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
170 int read_fifo = FALSE; |
7 | 171 |
172 /* | |
173 * The 'readonly' flag is only set when BF_NEVERLOADED is being reset. | |
174 * When re-entering the same buffer, it should not change, because the | |
175 * user may have reset the flag by hand. | |
176 */ | |
177 if (readonlymode && curbuf->b_ffname != NULL | |
178 && (curbuf->b_flags & BF_NEVERLOADED)) | |
179 curbuf->b_p_ro = TRUE; | |
180 | |
625 | 181 if (ml_open(curbuf) == FAIL) |
7 | 182 { |
183 /* | |
184 * There MUST be a memfile, otherwise we can't do anything | |
185 * If we can't create one for the current buffer, take another buffer | |
186 */ | |
3365 | 187 close_buffer(NULL, curbuf, 0, FALSE); |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
188 FOR_ALL_BUFFERS(curbuf) |
7 | 189 if (curbuf->b_ml.ml_mfp != NULL) |
190 break; | |
191 /* | |
17797
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
192 * If there is no memfile at all, exit. |
1698 | 193 * This is OK, since there are no changes to lose. |
7 | 194 */ |
195 if (curbuf == NULL) | |
196 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
197 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
|
198 |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
199 // 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
|
200 // will work. |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
201 v_dying = 2; |
7 | 202 getout(2); |
203 } | |
17797
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
204 |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
205 emsg(_("E83: Cannot allocate buffer, using other one...")); |
7 | 206 enter_buffer(curbuf); |
4139 | 207 #ifdef FEAT_SYN_HL |
208 if (old_tw != curbuf->b_p_tw) | |
209 check_colorcolumn(curwin); | |
210 #endif | |
7 | 211 return FAIL; |
212 } | |
213 | |
214 /* The autocommands in readfile() may change the buffer, but only AFTER | |
215 * reading the file. */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
216 set_bufref(&old_curbuf, curbuf); |
7 | 217 modified_was_set = FALSE; |
218 | |
219 /* mark cursor position as being invalid */ | |
2091
95b659982b7c
updated for version 7.2.375
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
220 curwin->w_valid = 0; |
7 | 221 |
222 if (curbuf->b_ffname != NULL | |
223 #ifdef FEAT_NETBEANS_INTG | |
224 && netbeansReadFile | |
225 #endif | |
226 ) | |
227 { | |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8441
diff
changeset
|
228 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
|
229 #ifdef UNIX |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
230 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
|
231 int perm; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
232 #endif |
7 | 233 #ifdef FEAT_NETBEANS_INTG |
234 int oldFire = netbeansFireChanges; | |
235 | |
236 netbeansFireChanges = 0; | |
237 #endif | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
238 #ifdef UNIX |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
239 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
|
240 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
|
241 || S_ISSOCK(perm) |
9911
74e345d2878c
commit https://github.com/vim/vim/commit/f04507d132fbcb63999167ec006fc6e700b5af4f
Christian Brabandt <cb@256bit.org>
parents:
9875
diff
changeset
|
242 # ifdef OPEN_CHR_FILES |
74e345d2878c
commit https://github.com/vim/vim/commit/f04507d132fbcb63999167ec006fc6e700b5af4f
Christian Brabandt <cb@256bit.org>
parents:
9875
diff
changeset
|
243 || (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
|
244 # endif |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
245 )) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
246 read_fifo = TRUE; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
247 if (read_fifo) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
248 curbuf->b_p_bin = TRUE; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
249 #endif |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8441
diff
changeset
|
250 if (shortmess(SHM_FILEINFO)) |
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8441
diff
changeset
|
251 msg_silent = 1; |
7 | 252 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
|
253 (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
|
254 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
|
255 #ifdef UNIX |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
256 if (read_fifo) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
257 { |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
258 curbuf->b_p_bin = save_bin; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
259 if (retval == OK) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
260 retval = read_buffer(FALSE, eap, flags); |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
261 } |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
262 #endif |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8441
diff
changeset
|
263 msg_silent = old_msg_silent; |
7 | 264 #ifdef FEAT_NETBEANS_INTG |
265 netbeansFireChanges = oldFire; | |
266 #endif | |
267 /* 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
|
268 if (bt_help(curbuf)) |
7 | 269 fix_help_buffer(); |
270 } | |
271 else if (read_stdin) | |
272 { | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
273 int save_bin = curbuf->b_p_bin; |
7 | 274 |
275 /* | |
276 * First read the text in binary mode into the buffer. | |
277 * Then read from that same buffer and append at the end. This makes | |
278 * it possible to retry when 'fileformat' or 'fileencoding' was | |
279 * guessed wrong. | |
280 */ | |
281 curbuf->b_p_bin = TRUE; | |
282 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
|
283 (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
|
284 flags | (READ_NEW + READ_STDIN)); |
7 | 285 curbuf->b_p_bin = save_bin; |
286 if (retval == OK) | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
287 retval = read_buffer(TRUE, eap, flags); |
7 | 288 } |
289 | |
290 /* if first time loading this buffer, init b_chartab[] */ | |
291 if (curbuf->b_flags & BF_NEVERLOADED) | |
5438 | 292 { |
7 | 293 (void)buf_init_chartab(curbuf, FALSE); |
5440 | 294 #ifdef FEAT_CINDENT |
5438 | 295 parse_cino(curbuf); |
5440 | 296 #endif |
5438 | 297 } |
7 | 298 |
299 /* | |
300 * Set/reset the Changed flag first, autocmds may change the buffer. | |
301 * 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
|
302 * So the modelines have priority over autocommands. |
7 | 303 */ |
304 /* When reading stdin, the buffer contents always needs writing, so set | |
305 * the changed flag. Unless in readonly mode: "ls | gview -". | |
306 * When interrupted and 'cpoptions' contains 'i' set changed flag. */ | |
1291 | 307 if ((got_int && vim_strchr(p_cpo, CPO_INTMOD) != NULL) |
7 | 308 || 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
|
309 #ifdef FEAT_EVAL |
7 | 310 || (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL) |
311 #endif | |
1291 | 312 ) |
7 | 313 changed(); |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
314 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
|
315 unchanged(curbuf, FALSE, TRUE); |
7 | 316 save_file_ff(curbuf); /* keep this fileformat */ |
317 | |
13519
4a44c90dd671
patch 8.0.1633: a TextChanged autocmd triggers when it is defined
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
318 /* Set last_changedtick to avoid triggering a TextChanged autocommand right |
4a44c90dd671
patch 8.0.1633: a TextChanged autocmd triggers when it is defined
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
319 * after it was added. */ |
4a44c90dd671
patch 8.0.1633: a TextChanged autocmd triggers when it is defined
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
320 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
|
321 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
|
322 |
7 | 323 /* require "!" to overwrite the file, because it wasn't read completely */ |
324 #ifdef FEAT_EVAL | |
325 if (aborting()) | |
326 #else | |
327 if (got_int) | |
328 #endif | |
329 curbuf->b_flags |= BF_READERR; | |
330 | |
20 | 331 #ifdef FEAT_FOLDING |
332 /* Need to update automatic folding. Do this before the autocommands, | |
333 * they may use the fold info. */ | |
334 foldUpdateAll(curwin); | |
335 #endif | |
336 | |
7 | 337 /* need to set w_topline, unless some autocommand already did that. */ |
338 if (!(curwin->w_valid & VALID_TOPLINE)) | |
339 { | |
340 curwin->w_topline = 1; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
341 #ifdef FEAT_DIFF |
7 | 342 curwin->w_topfill = 0; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
343 #endif |
7 | 344 } |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
345 #ifdef FEAT_EVAL |
7 | 346 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
|
347 #else |
7 | 348 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); |
349 #endif | |
350 | |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
351 if (retval == OK) |
7 | 352 { |
353 /* | |
354 * The autocommands may have changed the current buffer. Apply the | |
355 * modelines to the correct buffer, if it still exists and is loaded. | |
356 */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
357 if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL) |
7 | 358 { |
359 aco_save_T aco; | |
360 | |
361 /* 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
|
362 aucmd_prepbuf(&aco, old_curbuf.br_buf); |
717 | 363 do_modelines(0); |
7 | 364 curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); |
365 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
366 #ifdef FEAT_EVAL |
7 | 367 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
|
368 &retval); |
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
369 #else |
7 | 370 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
|
371 #endif |
7 | 372 |
373 /* restore curwin/curbuf and a few other things */ | |
374 aucmd_restbuf(&aco); | |
375 } | |
376 } | |
377 | |
378 return retval; | |
379 } | |
380 | |
381 /* | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
382 * 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
|
383 */ |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
384 void |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
385 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
|
386 { |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
387 bufref->br_buf = buf; |
11531
e349dc7889f5
patch 8.0.0648: possible use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
388 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
|
389 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
|
390 } |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
391 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
392 /* |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
393 * 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
|
394 * 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
|
395 * 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
|
396 * 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
|
397 * 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
|
398 */ |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
399 int |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
400 bufref_valid(bufref_T *bufref) |
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 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
|
403 ? 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
|
404 && 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
|
405 } |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
406 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
407 /* |
7 | 408 * 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
|
409 * This can be slow if there are many buffers, prefer using bufref_valid(). |
7 | 410 */ |
411 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
412 buf_valid(buf_T *buf) |
7 | 413 { |
414 buf_T *bp; | |
415 | |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
416 /* Assume that we more often have a recent buffer, start with the last |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
417 * one. */ |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
418 for (bp = lastbuf; bp != NULL; bp = bp->b_prev) |
7 | 419 if (bp == buf) |
420 return TRUE; | |
421 return FALSE; | |
422 } | |
423 | |
424 /* | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
425 * 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
|
426 */ |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
427 static hashtab_T buf_hashtab; |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
428 |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
429 static void |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
430 buf_hashtab_add(buf_T *buf) |
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 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
|
433 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
|
434 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
|
435 } |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
436 |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
437 static void |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
438 buf_hashtab_remove(buf_T *buf) |
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 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
|
441 |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
442 if (!HASHITEM_EMPTY(hi)) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
443 hash_remove(&buf_hashtab, hi); |
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 |
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
|
446 /* |
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
|
447 * 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
|
448 * 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
|
449 * 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
|
450 */ |
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 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
|
452 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
|
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 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
|
455 |
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 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
|
457 { |
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 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
|
459 |
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 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
|
461 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
|
462 { |
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
|
463 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
|
464 break; |
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 } |
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
|
467 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
|
468 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
|
469 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
|
470 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
|
471 } |
13720
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
472 |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
473 /* |
7 | 474 * Close the link to a buffer. |
475 * "action" is used when there is no longer a window for the buffer. | |
476 * It can be: | |
477 * 0 buffer becomes hidden | |
478 * DOBUF_UNLOAD buffer is unloaded | |
479 * DOBUF_DELETE buffer is unloaded and removed from buffer list | |
480 * 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
|
481 * DOBUF_WIPE_REUSE idem, and add to buf_reuse list |
7 | 482 * When doing all but the first one on the current buffer, the caller should |
483 * get a new buffer very soon! | |
484 * | |
485 * The 'bufhidden' option can force freeing and deleting. | |
3365 | 486 * |
487 * When "abort_if_last" is TRUE then do not close the buffer if autocommands | |
488 * cause there to be only one window with this buffer. e.g. when ":quit" is | |
489 * supposed to close the window but autocommands close all other windows. | |
7 | 490 */ |
491 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
492 close_buffer( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
493 win_T *win, /* if not NULL, set b_last_cursor */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
494 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
495 int action, |
16778
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
496 int abort_if_last) |
7 | 497 { |
498 int is_curbuf; | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
499 int nwindows; |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
500 bufref_T bufref; |
10320
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10184
diff
changeset
|
501 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
|
502 win_T *the_curwin = curwin; |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
503 tabpage_T *the_curtab = curtab; |
7 | 504 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
|
505 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
|
506 int del_buf = (action == DOBUF_DEL || wipe_buf); |
7 | 507 |
12479
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
508 /* |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
509 * 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
|
510 * 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
|
511 * "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
|
512 */ |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
513 if (buf->b_p_bh[0] == 'd') /* 'bufhidden' == "delete" */ |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
514 { |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
515 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
|
516 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
|
517 } |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
518 else if (buf->b_p_bh[0] == 'w') /* 'bufhidden' == "wipe" */ |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
519 { |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
520 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
|
521 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
|
522 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
|
523 } |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
524 else if (buf->b_p_bh[0] == 'u') /* 'bufhidden' == "unload" */ |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
525 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
|
526 |
11917
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
527 #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
|
528 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
|
529 { |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
530 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
|
531 { |
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
|
532 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
|
533 { |
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
|
534 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
|
535 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
|
536 |
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
|
537 /* 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
|
538 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
|
539 } |
11917
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
540 else |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
541 { |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
542 /* The job keeps running, hide the buffer. */ |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
543 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
|
544 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
|
545 } |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
546 } |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
547 else |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
548 { |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
549 /* A terminal buffer is wiped out if the job has finished. */ |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
550 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
|
551 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
|
552 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
|
553 } |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
554 } |
12479
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
555 #endif |
7 | 556 |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
557 /* Disallow deleting the buffer when it is locked (already being closed or |
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
558 * 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
|
559 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
|
560 return; |
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
561 |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
562 /* check no autocommands closed the window */ |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
563 if (win != NULL && win_valid_any_tab(win)) |
7 | 564 { |
565 /* Set b_last_cursor when closing the last window for the buffer. | |
566 * Remember the last cursor position and window options of the buffer. | |
567 * This used to be only for the current window, but then options like | |
568 * 'foldmethod' may be lost with a ":only" command. */ | |
569 if (buf->b_nwindows == 1) | |
570 set_last_cursor(win); | |
571 buflist_setfpos(buf, win, | |
572 win->w_cursor.lnum == 1 ? 0 : win->w_cursor.lnum, | |
573 win->w_cursor.col, TRUE); | |
574 } | |
575 | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
576 set_bufref(&bufref, buf); |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
577 |
7 | 578 /* When the buffer is no longer in a window, trigger BufWinLeave */ |
579 if (buf->b_nwindows == 1) | |
580 { | |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
581 ++buf->b_locked; |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
582 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
|
583 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
584 && !bufref_valid(&bufref)) |
3365 | 585 { |
3570 | 586 /* Autocommands deleted the buffer. */ |
587 aucmd_abort: | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
588 emsg(_(e_auabort)); |
7 | 589 return; |
3365 | 590 } |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
591 --buf->b_locked; |
3570 | 592 if (abort_if_last && one_window()) |
593 /* Autocommands made this the only window. */ | |
594 goto aucmd_abort; | |
7 | 595 |
596 /* When the buffer becomes hidden, but is not unloaded, trigger | |
597 * BufHidden */ | |
598 if (!unload_buf) | |
599 { | |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
600 ++buf->b_locked; |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
601 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
|
602 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
603 && !bufref_valid(&bufref)) |
3570 | 604 /* Autocommands deleted the buffer. */ |
605 goto aucmd_abort; | |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
606 --buf->b_locked; |
3570 | 607 if (abort_if_last && one_window()) |
608 /* Autocommands made this the only window. */ | |
609 goto aucmd_abort; | |
7 | 610 } |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
611 #ifdef FEAT_EVAL |
7 | 612 if (aborting()) /* autocmds may abort script processing */ |
613 return; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
614 #endif |
7 | 615 } |
10114
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
616 |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
617 /* If the buffer was in curwin and the window has changed, go back to that |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
618 * window, if it still exists. This avoids that ":edit x" triggering a |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
619 * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */ |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
620 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
|
621 { |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
622 block_autocmds(); |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
623 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
|
624 unblock_autocmds(); |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
625 } |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
626 |
7 | 627 nwindows = buf->b_nwindows; |
628 | |
629 /* decrease the link count from windows (unless not in any window) */ | |
630 if (buf->b_nwindows > 0) | |
631 --buf->b_nwindows; | |
632 | |
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
|
633 #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
|
634 if (diffopt_hiddenoff() && !unload_buf && buf->b_nwindows == 0) |
13170
6559e98f3e74
patch 8.0.1459: cannot handle change of directory
Christian Brabandt <cb@256bit.org>
parents:
13121
diff
changeset
|
635 diff_buf_delete(buf); /* Clear 'diff' for hidden buffer. */ |
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
|
636 #endif |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12684
diff
changeset
|
637 |
7 | 638 /* Return when a window is displaying the buffer or when it's not |
639 * unloaded. */ | |
640 if (buf->b_nwindows > 0 || !unload_buf) | |
641 return; | |
642 | |
643 /* Always remove the buffer when there is no file name. */ | |
644 if (buf->b_ffname == NULL) | |
645 del_buf = TRUE; | |
646 | |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10118
diff
changeset
|
647 /* When closing the current buffer stop Visual mode before freeing |
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10118
diff
changeset
|
648 * anything. */ |
10184
4669440016f2
commit https://github.com/vim/vim/commit/4930a76a0357f76a829eafe4985d04cf3ce0e9e0
Christian Brabandt <cb@256bit.org>
parents:
10156
diff
changeset
|
649 if (buf == curbuf && VIsual_active |
10156
f1ad88f3834c
commit https://github.com/vim/vim/commit/9a27c7fde6d453d9892b6f6baa756bce4d6d419d
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
650 #if defined(EXITFREE) |
f1ad88f3834c
commit https://github.com/vim/vim/commit/9a27c7fde6d453d9892b6f6baa756bce4d6d419d
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
651 && !entered_free_all_mem |
f1ad88f3834c
commit https://github.com/vim/vim/commit/9a27c7fde6d453d9892b6f6baa756bce4d6d419d
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
652 #endif |
f1ad88f3834c
commit https://github.com/vim/vim/commit/9a27c7fde6d453d9892b6f6baa756bce4d6d419d
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
653 ) |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10118
diff
changeset
|
654 end_visual_mode(); |
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10118
diff
changeset
|
655 |
7 | 656 /* |
657 * Free all things allocated for this buffer. | |
658 * Also calls the "BufDelete" autocommands when del_buf is TRUE. | |
659 */ | |
660 /* Remember if we are closing the current buffer. Restore the number of | |
661 * windows, so that autocommands in buf_freeall() don't get confused. */ | |
662 is_curbuf = (buf == curbuf); | |
663 buf->b_nwindows = nwindows; | |
664 | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
665 buf_freeall(buf, (del_buf ? BFA_DEL : 0) + (wipe_buf ? BFA_WIPE : 0)); |
7 | 666 |
667 /* 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
|
668 if (!bufref_valid(&bufref)) |
7 | 669 return; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
670 #ifdef FEAT_EVAL |
20 | 671 if (aborting()) /* autocmds may abort script processing */ |
7 | 672 return; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
673 #endif |
7 | 674 |
675 /* | |
676 * It's possible that autocommands change curbuf to the one being deleted. | |
677 * This might cause the previous curbuf to be deleted unexpectedly. But | |
678 * in some cases it's OK to delete the curbuf, because a new one is | |
679 * obtained anyway. Therefore only return if curbuf changed to the | |
680 * deleted buffer. | |
681 */ | |
682 if (buf == curbuf && !is_curbuf) | |
683 return; | |
9450
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
684 |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
685 if (win_valid_any_tab(win) && win->w_buffer == buf) |
9450
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
686 win->w_buffer = NULL; /* make sure we don't use the buffer now */ |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
687 |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
688 /* Autocommands may have opened or closed windows for this buffer. |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
689 * Decrement the count for the close we do here. */ |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
690 if (buf->b_nwindows > 0) |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
691 --buf->b_nwindows; |
7 | 692 |
693 /* | |
694 * Remove the buffer from the list. | |
695 */ | |
696 if (wipe_buf) | |
697 { | |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
698 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
|
699 { |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
700 // 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
|
701 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
|
702 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
|
703 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
|
704 ((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
|
705 } |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
706 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
|
707 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
|
708 else |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
709 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
|
710 VIM_CLEAR(buf->b_ffname); |
7 | 711 if (buf->b_prev == NULL) |
712 firstbuf = buf->b_next; | |
713 else | |
714 buf->b_prev->b_next = buf->b_next; | |
715 if (buf->b_next == NULL) | |
716 lastbuf = buf->b_prev; | |
717 else | |
718 buf->b_next->b_prev = buf->b_prev; | |
719 free_buffer(buf); | |
720 } | |
721 else | |
722 { | |
723 if (del_buf) | |
724 { | |
725 /* Free all internal variables and reset option values, to make | |
726 * ":bdel" compatible with Vim 5.7. */ | |
727 free_buffer_stuff(buf, TRUE); | |
728 | |
729 /* Make it look like a new buffer. */ | |
730 buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED; | |
731 | |
732 /* Init the options when loaded again. */ | |
733 buf->b_p_initialized = FALSE; | |
734 } | |
735 buf_clear_file(buf); | |
736 if (del_buf) | |
737 buf->b_p_bl = FALSE; | |
738 } | |
739 } | |
740 | |
741 /* | |
742 * Make buffer not contain a file. | |
743 */ | |
744 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
745 buf_clear_file(buf_T *buf) |
7 | 746 { |
747 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
|
748 unchanged(buf, TRUE, TRUE); |
7 | 749 buf->b_shortname = FALSE; |
750 buf->b_p_eol = TRUE; | |
751 buf->b_start_eol = TRUE; | |
752 buf->b_p_bomb = FALSE; | |
1352 | 753 buf->b_start_bomb = FALSE; |
7 | 754 buf->b_ml.ml_mfp = NULL; |
755 buf->b_ml.ml_flags = ML_EMPTY; /* empty buffer */ | |
756 #ifdef FEAT_NETBEANS_INTG | |
757 netbeans_deleted_all_lines(buf); | |
758 #endif | |
759 } | |
760 | |
761 /* | |
762 * 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
|
763 * 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
|
764 * flags: |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
765 * BFA_DEL buffer is going to be deleted |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
766 * BFA_WIPE buffer is going to be wiped out |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
767 * BFA_KEEP_UNDO do not free undo information |
7 | 768 */ |
769 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
770 buf_freeall(buf_T *buf, int flags) |
7 | 771 { |
772 int is_curbuf = (buf == curbuf); | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
773 bufref_T bufref; |
10118
5d77565e6222
commit https://github.com/vim/vim/commit/030cddc7ec0c3d2fe3969140cd1b92b2f18633c0
Christian Brabandt <cb@256bit.org>
parents:
10114
diff
changeset
|
774 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
|
775 win_T *the_curwin = curwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
776 tabpage_T *the_curtab = curtab; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
777 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
778 /* 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
|
779 ++buf->b_locked; |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
780 set_bufref(&bufref, buf); |
9106
97a9538c37ff
commit https://github.com/vim/vim/commit/c67e89213476b5f4756d92208b57ce9ef4a4cf24
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
781 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
|
782 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
783 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
|
784 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
785 && !bufref_valid(&bufref)) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
786 /* autocommands deleted the buffer */ |
9106
97a9538c37ff
commit https://github.com/vim/vim/commit/c67e89213476b5f4756d92208b57ce9ef4a4cf24
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
787 return; |
97a9538c37ff
commit https://github.com/vim/vim/commit/c67e89213476b5f4756d92208b57ce9ef4a4cf24
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
788 } |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
789 if ((flags & BFA_DEL) && buf->b_p_bl) |
7 | 790 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
791 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
|
792 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
793 && !bufref_valid(&bufref)) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
794 /* autocommands deleted the buffer */ |
7 | 795 return; |
796 } | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
797 if (flags & BFA_WIPE) |
7 | 798 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
799 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
|
800 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
801 && !bufref_valid(&bufref)) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
802 /* autocommands deleted the buffer */ |
7 | 803 return; |
804 } | |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
805 --buf->b_locked; |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
806 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
807 /* If the buffer was in curwin and the window has changed, go back to that |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
808 * window, if it still exists. This avoids that ":edit x" triggering a |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
809 * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */ |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
810 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
|
811 { |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
812 block_autocmds(); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
813 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
|
814 unblock_autocmds(); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
815 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
816 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
817 #ifdef FEAT_EVAL |
36 | 818 if (aborting()) /* autocmds may abort script processing */ |
7 | 819 return; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
820 #endif |
7 | 821 |
822 /* | |
823 * It's possible that autocommands change curbuf to the one being deleted. | |
824 * This might cause curbuf to be deleted unexpectedly. But in some cases | |
825 * it's OK to delete the curbuf, because a new one is obtained anyway. | |
826 * Therefore only return if curbuf changed to the deleted buffer. | |
827 */ | |
828 if (buf == curbuf && !is_curbuf) | |
829 return; | |
830 #ifdef FEAT_DIFF | |
831 diff_buf_delete(buf); /* Can't use 'diff' for unloaded buffer. */ | |
832 #endif | |
3068 | 833 #ifdef FEAT_SYN_HL |
3182 | 834 /* Remove any ownsyntax, unless exiting. */ |
10118
5d77565e6222
commit https://github.com/vim/vim/commit/030cddc7ec0c3d2fe3969140cd1b92b2f18633c0
Christian Brabandt <cb@256bit.org>
parents:
10114
diff
changeset
|
835 if (curwin != NULL && curwin->w_buffer == buf) |
3182 | 836 reset_synblock(curwin); |
3068 | 837 #endif |
1187 | 838 |
839 #ifdef FEAT_FOLDING | |
840 /* No folds in an empty buffer. */ | |
841 { | |
842 win_T *win; | |
843 tabpage_T *tp; | |
844 | |
845 FOR_ALL_TAB_WINDOWS(tp, win) | |
846 if (win->w_buffer == buf) | |
847 clearFolding(win); | |
848 } | |
849 #endif | |
850 | |
7 | 851 #ifdef FEAT_TCL |
852 tcl_buffer_free(buf); | |
853 #endif | |
854 ml_close(buf, TRUE); /* close and delete the memline/memfile */ | |
855 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
|
856 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
|
857 { |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
858 u_blockfree(buf); /* free the memory allocated for undo */ |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
859 u_clearall(buf); /* reset all undo information */ |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
860 } |
7 | 861 #ifdef FEAT_SYN_HL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
862 syntax_clear(&buf->b_s); /* reset syntax info */ |
7 | 863 #endif |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
15056
diff
changeset
|
864 #ifdef FEAT_TEXT_PROP |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
15056
diff
changeset
|
865 clear_buf_prop_types(buf); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
15056
diff
changeset
|
866 #endif |
24 | 867 buf->b_flags &= ~BF_READERR; /* a read error is no longer relevant */ |
7 | 868 } |
869 | |
870 /* | |
871 * Free a buffer structure and the things it contains related to the buffer | |
872 * itself (not the file, that must have been done already). | |
873 */ | |
874 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
875 free_buffer(buf_T *buf) |
7 | 876 { |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
877 ++buf_free_count; |
7 | 878 free_buffer_stuff(buf, TRUE); |
4287 | 879 #ifdef FEAT_EVAL |
12630
560adb3eed8b
patch 8.0.1193: crash when wiping out a buffer after using getbufinfo()
Christian Brabandt <cb@256bit.org>
parents:
12572
diff
changeset
|
880 /* b:changedtick uses an item in buf_T, remove it now */ |
560adb3eed8b
patch 8.0.1193: crash when wiping out a buffer after using getbufinfo()
Christian Brabandt <cb@256bit.org>
parents:
12572
diff
changeset
|
881 dictitem_remove(buf->b_vars, (dictitem_T *)&buf->b_ct_di); |
4287 | 882 unref_var_dict(buf->b_vars); |
883 #endif | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
884 #ifdef FEAT_LUA |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
885 lua_buffer_free(buf); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
886 #endif |
14 | 887 #ifdef FEAT_MZSCHEME |
888 mzscheme_buffer_free(buf); | |
889 #endif | |
7 | 890 #ifdef FEAT_PERL |
891 perl_buf_free(buf); | |
892 #endif | |
893 #ifdef FEAT_PYTHON | |
894 python_buffer_free(buf); | |
895 #endif | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
896 #ifdef FEAT_PYTHON3 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
897 python3_buffer_free(buf); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
898 #endif |
7 | 899 #ifdef FEAT_RUBY |
900 ruby_buffer_free(buf); | |
901 #endif | |
9087
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
902 #ifdef FEAT_JOB_CHANNEL |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
903 channel_buffer_free(buf); |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
904 #endif |
11690
ce434212d682
patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents:
11531
diff
changeset
|
905 #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
|
906 free_terminal(buf); |
11690
ce434212d682
patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents:
11531
diff
changeset
|
907 #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
|
908 #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
|
909 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
|
910 free_callback(&buf->b_prompt_callback); |
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
|
911 #endif |
9515
bb538c090668
commit https://github.com/vim/vim/commit/9280e3f95d065733f04fa22869e5ef071d531931
Christian Brabandt <cb@256bit.org>
parents:
9511
diff
changeset
|
912 |
bb538c090668
commit https://github.com/vim/vim/commit/9280e3f95d065733f04fa22869e5ef071d531931
Christian Brabandt <cb@256bit.org>
parents:
9511
diff
changeset
|
913 buf_hashtab_remove(buf); |
bb538c090668
commit https://github.com/vim/vim/commit/9280e3f95d065733f04fa22869e5ef071d531931
Christian Brabandt <cb@256bit.org>
parents:
9511
diff
changeset
|
914 |
40 | 915 aubuflocal_remove(buf); |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
916 |
5816 | 917 if (autocmd_busy) |
918 { | |
919 /* Do not free the buffer structure while autocommands are executing, | |
920 * it's still needed. Free it when autocmd_busy is reset. */ | |
921 buf->b_next = au_pending_free_buf; | |
922 au_pending_free_buf = buf; | |
923 } | |
924 else | |
925 vim_free(buf); | |
7 | 926 } |
927 | |
928 /* | |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
929 * 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
|
930 */ |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
931 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
|
932 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
|
933 { |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
934 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
|
935 |
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
936 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
|
937 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
|
938 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
|
939 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
|
940 |
10954
8ff62b4cffae
patch 8.0.0366: build fails with tiny features
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
941 #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
|
942 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
|
943 (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
|
944 #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
|
945 } |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
946 |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
947 /* |
7 | 948 * Free stuff in the buffer for ":bdel" and when wiping out the buffer. |
949 */ | |
950 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
951 free_buffer_stuff( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
952 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
953 int free_options) /* free options as well */ |
7 | 954 { |
955 if (free_options) | |
956 { | |
957 clear_wininfo(buf); /* including window-local options */ | |
958 free_buf_options(buf, TRUE); | |
2620 | 959 #ifdef FEAT_SPELL |
960 ga_clear(&buf->b_s.b_langp); | |
961 #endif | |
7 | 962 } |
963 #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
|
964 { |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
965 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
|
966 |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
967 vars_clear(&buf->b_vars->dv_hashtab); /* free all buffer variables */ |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
968 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
|
969 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
|
970 CHANGEDTICK(buf) = tick; |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
971 } |
7 | 972 #endif |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
16261
diff
changeset
|
973 uc_clear(&buf->b_ucmds); // clear local user commands |
7 | 974 #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
|
975 buf_delete_signs(buf, (char_u *)"*"); // delete any signs |
7 | 976 #endif |
1781 | 977 #ifdef FEAT_NETBEANS_INTG |
2210 | 978 netbeans_file_killed(buf); |
1781 | 979 #endif |
7 | 980 map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); /* clear local mappings */ |
981 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
|
982 VIM_CLEAR(buf->b_start_fenc); |
7 | 983 } |
984 | |
985 /* | |
986 * Free the b_wininfo list for buffer "buf". | |
987 */ | |
988 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
989 clear_wininfo(buf_T *buf) |
7 | 990 { |
991 wininfo_T *wip; | |
992 | |
993 while (buf->b_wininfo != NULL) | |
994 { | |
995 wip = buf->b_wininfo; | |
996 buf->b_wininfo = wip->wi_next; | |
997 if (wip->wi_optset) | |
998 { | |
999 clear_winopt(&wip->wi_opt); | |
1000 #ifdef FEAT_FOLDING | |
1001 deleteFoldRecurse(&wip->wi_folds); | |
1002 #endif | |
1003 } | |
1004 vim_free(wip); | |
1005 } | |
1006 } | |
1007 | |
1008 /* | |
1009 * Go to another buffer. Handles the result of the ATTENTION dialog. | |
1010 */ | |
1011 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1012 goto_buffer( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1013 exarg_T *eap, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1014 int start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1015 int dir, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1016 int count) |
7 | 1017 { |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1018 bufref_T old_curbuf; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1019 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1020 set_bufref(&old_curbuf, curbuf); |
7 | 1021 |
1022 swap_exists_action = SEA_DIALOG; | |
1023 (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, | |
1024 start, dir, count, eap->forceit); | |
1025 if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') | |
1026 { | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1027 #if defined(FEAT_EVAL) |
24 | 1028 cleanup_T cs; |
1029 | |
1030 /* Reset the error/interrupt/exception state here so that | |
1031 * aborting() returns FALSE when closing a window. */ | |
1032 enter_cleanup(&cs); | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1033 #endif |
24 | 1034 |
1035 /* Quitting means closing the split window, nothing else. */ | |
7 | 1036 win_close(curwin, TRUE); |
1037 swap_exists_action = SEA_NONE; | |
602 | 1038 swap_exists_did_quit = TRUE; |
24 | 1039 |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1040 #if defined(FEAT_EVAL) |
24 | 1041 /* Restore the error/interrupt/exception state if not discarded by a |
1042 * new aborting error, interrupt, or uncaught exception. */ | |
1043 leave_cleanup(&cs); | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1044 #endif |
7 | 1045 } |
1046 else | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1047 handle_swap_exists(&old_curbuf); |
7 | 1048 } |
1049 | |
1050 /* | |
1051 * Handle the situation of swap_exists_action being set. | |
1052 * It is allowed for "old_curbuf" to be NULL or invalid. | |
1053 */ | |
1054 void | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1055 handle_swap_exists(bufref_T *old_curbuf) |
7 | 1056 { |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1057 #if defined(FEAT_EVAL) |
24 | 1058 cleanup_T cs; |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1059 #endif |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1060 #ifdef FEAT_SYN_HL |
4139 | 1061 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
|
1062 #endif |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1063 buf_T *buf; |
20 | 1064 |
7 | 1065 if (swap_exists_action == SEA_QUIT) |
1066 { | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1067 #if defined(FEAT_EVAL) |
24 | 1068 /* Reset the error/interrupt/exception state here so that |
1069 * aborting() returns FALSE when closing a buffer. */ | |
1070 enter_cleanup(&cs); | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1071 #endif |
24 | 1072 |
7 | 1073 /* User selected Quit at ATTENTION prompt. Go back to previous |
1074 * buffer. If that buffer is gone or the same as the current one, | |
1075 * open a new, empty buffer. */ | |
1076 swap_exists_action = SEA_NONE; /* don't want it again */ | |
602 | 1077 swap_exists_did_quit = TRUE; |
3365 | 1078 close_buffer(curwin, curbuf, DOBUF_UNLOAD, FALSE); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1079 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
|
1080 || old_curbuf->br_buf == curbuf) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1081 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
|
1082 else |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1083 buf = old_curbuf->br_buf; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1084 if (buf != NULL) |
4139 | 1085 { |
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
|
1086 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
|
1087 |
b6b2f7d69c7f
patch 8.1.0310: file info msg not always suppressed with 'F' in 'shortmess'
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1088 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
|
1089 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
|
1090 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
|
1091 // 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
|
1092 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
|
1093 |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1094 #ifdef FEAT_SYN_HL |
4139 | 1095 if (old_tw != curbuf->b_p_tw) |
1096 check_colorcolumn(curwin); | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1097 #endif |
4139 | 1098 } |
7 | 1099 /* If "old_curbuf" is NULL we are in big trouble here... */ |
24 | 1100 |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1101 #if defined(FEAT_EVAL) |
24 | 1102 /* Restore the error/interrupt/exception state if not discarded by a |
1103 * new aborting error, interrupt, or uncaught exception. */ | |
1104 leave_cleanup(&cs); | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1105 #endif |
7 | 1106 } |
1107 else if (swap_exists_action == SEA_RECOVER) | |
1108 { | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1109 #if defined(FEAT_EVAL) |
24 | 1110 /* Reset the error/interrupt/exception state here so that |
1111 * aborting() returns FALSE when closing a buffer. */ | |
1112 enter_cleanup(&cs); | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1113 #endif |
24 | 1114 |
7 | 1115 /* User selected Recover at ATTENTION prompt. */ |
1116 msg_scroll = TRUE; | |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16664
diff
changeset
|
1117 ml_recover(FALSE); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
1118 msg_puts("\n"); /* don't overwrite the last message */ |
7 | 1119 cmdline_row = msg_row; |
717 | 1120 do_modelines(0); |
24 | 1121 |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1122 #if defined(FEAT_EVAL) |
24 | 1123 /* Restore the error/interrupt/exception state if not discarded by a |
1124 * new aborting error, interrupt, or uncaught exception. */ | |
1125 leave_cleanup(&cs); | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1126 #endif |
7 | 1127 } |
1128 swap_exists_action = SEA_NONE; | |
1129 } | |
1130 | |
1131 /* | |
1132 * do_bufdel() - delete or unload buffer(s) | |
1133 * | |
1134 * addr_count == 0: ":bdel" - delete current buffer | |
1135 * addr_count == 1: ":N bdel" or ":bdel N [N ..]" - first delete | |
1136 * buffer "end_bnr", then any other arguments. | |
1137 * addr_count == 2: ":N,N bdel" - delete buffers in range | |
1138 * | |
1139 * command can be DOBUF_UNLOAD (":bunload"), DOBUF_WIPE (":bwipeout") or | |
1140 * DOBUF_DEL (":bdel") | |
1141 * | |
1142 * Returns error message or NULL | |
1143 */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1144 char * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1145 do_bufdel( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1146 int command, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1147 char_u *arg, /* pointer to extra arguments */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1148 int addr_count, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1149 int start_bnr, /* first buffer number in a range */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1150 int end_bnr, /* buffer nr or last buffer nr in a range */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1151 int forceit) |
7 | 1152 { |
1153 int do_current = 0; /* delete current buffer? */ | |
1154 int deleted = 0; /* number of buffers deleted */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1155 char *errormsg = NULL; /* return value */ |
7 | 1156 int bnr; /* buffer number */ |
1157 char_u *p; | |
1158 | |
1159 if (addr_count == 0) | |
1160 { | |
1161 (void)do_buffer(command, DOBUF_CURRENT, FORWARD, 0, forceit); | |
1162 } | |
1163 else | |
1164 { | |
1165 if (addr_count == 2) | |
1166 { | |
1167 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
|
1168 return _(e_trailing); |
7 | 1169 bnr = start_bnr; |
1170 } | |
1171 else /* addr_count == 1 */ | |
1172 bnr = end_bnr; | |
1173 | |
1174 for ( ;!got_int; ui_breakcheck()) | |
1175 { | |
1176 /* | |
1177 * delete the current buffer last, otherwise when the | |
1178 * current buffer is deleted, the next buffer becomes | |
1179 * the current one and will be loaded, which may then | |
1180 * also be deleted, etc. | |
1181 */ | |
1182 if (bnr == curbuf->b_fnum) | |
1183 do_current = bnr; | |
1184 else if (do_buffer(command, DOBUF_FIRST, FORWARD, (int)bnr, | |
1185 forceit) == OK) | |
1186 ++deleted; | |
1187 | |
1188 /* | |
1189 * find next buffer number to delete/unload | |
1190 */ | |
1191 if (addr_count == 2) | |
1192 { | |
1193 if (++bnr > end_bnr) | |
1194 break; | |
1195 } | |
1196 else /* addr_count == 1 */ | |
1197 { | |
1198 arg = skipwhite(arg); | |
1199 if (*arg == NUL) | |
1200 break; | |
1201 if (!VIM_ISDIGIT(*arg)) | |
1202 { | |
1203 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
|
1204 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
|
1205 command == DOBUF_WIPE || command == DOBUF_WIPE_REUSE, |
4236 | 1206 FALSE, FALSE); |
7 | 1207 if (bnr < 0) /* failed */ |
1208 break; | |
1209 arg = p; | |
1210 } | |
1211 else | |
1212 bnr = getdigits(&arg); | |
1213 } | |
1214 } | |
1215 if (!got_int && do_current && do_buffer(command, DOBUF_FIRST, | |
1216 FORWARD, do_current, forceit) == OK) | |
1217 ++deleted; | |
1218 | |
1219 if (deleted == 0) | |
1220 { | |
1221 if (command == DOBUF_UNLOAD) | |
300 | 1222 STRCPY(IObuff, _("E515: No buffers were unloaded")); |
7 | 1223 else if (command == DOBUF_DEL) |
300 | 1224 STRCPY(IObuff, _("E516: No buffers were deleted")); |
7 | 1225 else |
300 | 1226 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
|
1227 errormsg = (char *)IObuff; |
7 | 1228 } |
1229 else if (deleted >= p_report) | |
1230 { | |
1231 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
|
1232 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
|
1233 "%d buffers unloaded", deleted), deleted); |
7 | 1234 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
|
1235 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
|
1236 "%d buffers deleted", deleted), deleted); |
7 | 1237 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1238 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
|
1239 "%d buffers wiped out", deleted), deleted); |
7 | 1240 } |
1241 } | |
1242 | |
1243 | |
1244 return errormsg; | |
1245 } | |
1246 | |
5586 | 1247 /* |
1248 * Make the current buffer empty. | |
1249 * Used when it is wiped out and it's the last buffer. | |
1250 */ | |
1251 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1252 empty_curbuf( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1253 int close_others, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1254 int forceit, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1255 int action) |
5586 | 1256 { |
1257 int retval; | |
1258 buf_T *buf = curbuf; | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1259 bufref_T bufref; |
5586 | 1260 |
1261 if (action == DOBUF_UNLOAD) | |
1262 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1263 emsg(_("E90: Cannot unload last buffer")); |
5586 | 1264 return FAIL; |
1265 } | |
1266 | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1267 set_bufref(&bufref, buf); |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1268 if (close_others) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1269 /* Close any other windows on this buffer, then make it empty. */ |
5586 | 1270 close_windows(buf, TRUE); |
1271 | |
1272 setpcmark(); | |
1273 retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, | |
1274 forceit ? ECMD_FORCEIT : 0, curwin); | |
1275 | |
1276 /* | |
1277 * do_ecmd() may create a new buffer, then we have to delete | |
1278 * the old one. But do_ecmd() may have done that already, check | |
1279 * if the buffer still exists. | |
1280 */ | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1281 if (buf != curbuf && bufref_valid(&bufref) && buf->b_nwindows == 0) |
5586 | 1282 close_buffer(NULL, buf, action, FALSE); |
1283 if (!close_others) | |
1284 need_fileinfo = FALSE; | |
1285 return retval; | |
1286 } | |
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
|
1287 |
7 | 1288 /* |
1289 * Implementation of the commands for the buffer list. | |
1290 * | |
1291 * action == DOBUF_GOTO go to specified buffer | |
1292 * action == DOBUF_SPLIT split window and go to specified buffer | |
1293 * action == DOBUF_UNLOAD unload specified buffer(s) | |
1294 * action == DOBUF_DEL delete specified buffer(s) from buffer list | |
1295 * 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
|
1296 * action == DOBUF_WIPE_REUSE idem, and add number to "buf_reuse" |
7 | 1297 * |
1298 * start == DOBUF_CURRENT go to "count" buffer from current buffer | |
1299 * start == DOBUF_FIRST go to "count" buffer from first buffer | |
1300 * start == DOBUF_LAST go to "count" buffer from last buffer | |
1301 * start == DOBUF_MOD go to "count" modified buffer from current buffer | |
1302 * | |
1303 * Return FAIL or OK. | |
1304 */ | |
1305 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1306 do_buffer( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1307 int action, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1308 int start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1309 int dir, /* FORWARD or BACKWARD */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1310 int count, /* buffer number or number of buffers */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1311 int forceit) /* TRUE for :...! */ |
7 | 1312 { |
1313 buf_T *buf; | |
1314 buf_T *bp; | |
1315 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
|
1316 || action == DOBUF_WIPE || action == DOBUF_WIPE_REUSE); |
7 | 1317 |
1318 switch (start) | |
1319 { | |
1320 case DOBUF_FIRST: buf = firstbuf; break; | |
1321 case DOBUF_LAST: buf = lastbuf; break; | |
1322 default: buf = curbuf; break; | |
1323 } | |
1324 if (start == DOBUF_MOD) /* find next modified buffer */ | |
1325 { | |
1326 while (count-- > 0) | |
1327 { | |
1328 do | |
1329 { | |
1330 buf = buf->b_next; | |
1331 if (buf == NULL) | |
1332 buf = firstbuf; | |
1333 } | |
1334 while (buf != curbuf && !bufIsChanged(buf)); | |
1335 } | |
1336 if (!bufIsChanged(buf)) | |
1337 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1338 emsg(_("E84: No modified buffer found")); |
7 | 1339 return FAIL; |
1340 } | |
1341 } | |
1342 else if (start == DOBUF_FIRST && count) /* find specified buffer number */ | |
1343 { | |
1344 while (buf != NULL && buf->b_fnum != count) | |
1345 buf = buf->b_next; | |
1346 } | |
1347 else | |
1348 { | |
1349 bp = NULL; | |
1350 while (count > 0 || (!unload && !buf->b_p_bl && bp != buf)) | |
1351 { | |
1352 /* remember the buffer where we start, we come back there when all | |
1353 * buffers are unlisted. */ | |
1354 if (bp == NULL) | |
1355 bp = buf; | |
1356 if (dir == FORWARD) | |
1357 { | |
1358 buf = buf->b_next; | |
1359 if (buf == NULL) | |
1360 buf = firstbuf; | |
1361 } | |
1362 else | |
1363 { | |
1364 buf = buf->b_prev; | |
1365 if (buf == NULL) | |
1366 buf = lastbuf; | |
1367 } | |
1368 /* don't count unlisted buffers */ | |
1369 if (unload || buf->b_p_bl) | |
1370 { | |
1371 --count; | |
1372 bp = NULL; /* use this buffer as new starting point */ | |
1373 } | |
1374 if (bp == buf) | |
1375 { | |
1376 /* 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
|
1377 emsg(_("E85: There is no listed buffer")); |
7 | 1378 return FAIL; |
1379 } | |
1380 } | |
1381 } | |
1382 | |
1383 if (buf == NULL) /* could not find it */ | |
1384 { | |
1385 if (start == DOBUF_FIRST) | |
1386 { | |
1387 /* don't warn when deleting */ | |
1388 if (!unload) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1389 semsg(_(e_nobufnr), count); |
7 | 1390 } |
1391 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
|
1392 emsg(_("E87: Cannot go beyond last buffer")); |
7 | 1393 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1394 emsg(_("E88: Cannot go before first buffer")); |
7 | 1395 return FAIL; |
1396 } | |
1397 | |
1398 #ifdef FEAT_GUI | |
1399 need_mouse_correct = TRUE; | |
1400 #endif | |
1401 | |
1402 /* | |
1403 * delete buffer buf from memory and/or the list | |
1404 */ | |
1405 if (unload) | |
1406 { | |
1407 int forward; | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1408 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1409 |
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
|
1410 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
|
1411 return FAIL; |
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
1412 |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1413 set_bufref(&bufref, buf); |
7 | 1414 |
1415 /* When unloading or deleting a buffer that's already unloaded and | |
1416 * 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
|
1417 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
|
1418 && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl) |
7 | 1419 return FAIL; |
1420 | |
1421 if (!forceit && bufIsChanged(buf)) | |
1422 { | |
13553
04019fc3de93
patch 8.0.1650: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13535
diff
changeset
|
1423 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
7 | 1424 if ((p_confirm || cmdmod.confirm) && p_write) |
1425 { | |
1426 dialog_changed(buf, FALSE); | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1427 if (!bufref_valid(&bufref)) |
7 | 1428 /* Autocommand deleted buffer, oops! It's not changed |
1429 * now. */ | |
1430 return FAIL; | |
36 | 1431 /* If it's still changed fail silently, the dialog already |
1432 * mentioned why it fails. */ | |
1433 if (bufIsChanged(buf)) | |
1434 return FAIL; | |
7 | 1435 } |
36 | 1436 else |
13553
04019fc3de93
patch 8.0.1650: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13535
diff
changeset
|
1437 #endif |
7 | 1438 { |
15490
98c35d312987
patch 8.1.0753: printf format not checked for semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1439 semsg(_("E89: No write since last change for buffer %d (add ! to override)"), |
7 | 1440 buf->b_fnum); |
1441 return FAIL; | |
1442 } | |
1443 } | |
1444 | |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10118
diff
changeset
|
1445 /* 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
|
1446 if (buf == curbuf && VIsual_active) |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10118
diff
changeset
|
1447 end_visual_mode(); |
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10118
diff
changeset
|
1448 |
7 | 1449 /* |
1450 * If deleting the last (listed) buffer, make it empty. | |
1451 * The last (listed) buffer cannot be unloaded. | |
1452 */ | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
1453 FOR_ALL_BUFFERS(bp) |
7 | 1454 if (bp->b_p_bl && bp != buf) |
1455 break; | |
1456 if (bp == NULL && buf == curbuf) | |
5586 | 1457 return empty_curbuf(TRUE, forceit, action); |
7 | 1458 |
1459 /* | |
1460 * If the deleted buffer is the current one, close the current window | |
671 | 1461 * (unless it's the only window). Repeat this so long as we end up in |
1462 * a window with this buffer. | |
7 | 1463 */ |
671 | 1464 while (buf == curbuf |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
1465 && !(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
|
1466 && (!ONE_WINDOW || first_tabpage->tp_next != NULL)) |
5302 | 1467 { |
1468 if (win_close(curwin, FALSE) == FAIL) | |
1469 break; | |
1470 } | |
7 | 1471 |
1472 /* | |
1473 * If the buffer to be deleted is not the current one, delete it here. | |
1474 */ | |
1475 if (buf != curbuf) | |
1476 { | |
671 | 1477 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
|
1478 if (buf != curbuf && bufref_valid(&bufref) && buf->b_nwindows <= 0) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1479 close_buffer(NULL, buf, action, FALSE); |
7 | 1480 return OK; |
1481 } | |
1482 | |
1483 /* | |
1484 * Deleting the current buffer: Need to find another buffer to go to. | |
5586 | 1485 * There should be another, otherwise it would have been handled |
1486 * 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
|
1487 * First use au_new_curbuf.br_buf, if it is valid. |
7 | 1488 * Then prefer the buffer we most recently visited. |
1489 * Else try to find one that is loaded, after the current buffer, | |
1490 * then before the current buffer. | |
1491 * Finally use any buffer. | |
1492 */ | |
1493 buf = NULL; /* selected buffer */ | |
1494 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
|
1495 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
|
1496 buf = au_new_curbuf.br_buf; |
7 | 1497 #ifdef FEAT_JUMPLIST |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1498 else if (curwin->w_jumplistlen > 0) |
7 | 1499 { |
1500 int jumpidx; | |
1501 | |
1502 jumpidx = curwin->w_jumplistidx - 1; | |
1503 if (jumpidx < 0) | |
1504 jumpidx = curwin->w_jumplistlen - 1; | |
1505 | |
1506 forward = jumpidx; | |
1507 while (jumpidx != curwin->w_jumplistidx) | |
1508 { | |
1509 buf = buflist_findnr(curwin->w_jumplist[jumpidx].fmark.fnum); | |
1510 if (buf != NULL) | |
1511 { | |
1512 if (buf == curbuf || !buf->b_p_bl) | |
1513 buf = NULL; /* skip current and unlisted bufs */ | |
1514 else if (buf->b_ml.ml_mfp == NULL) | |
1515 { | |
1516 /* skip unloaded buf, but may keep it for later */ | |
1517 if (bp == NULL) | |
1518 bp = buf; | |
1519 buf = NULL; | |
1520 } | |
1521 } | |
1522 if (buf != NULL) /* found a valid buffer: stop searching */ | |
1523 break; | |
1524 /* advance to older entry in jump list */ | |
1525 if (!jumpidx && curwin->w_jumplistidx == curwin->w_jumplistlen) | |
1526 break; | |
1527 if (--jumpidx < 0) | |
1528 jumpidx = curwin->w_jumplistlen - 1; | |
1529 if (jumpidx == forward) /* List exhausted for sure */ | |
1530 break; | |
1531 } | |
1532 } | |
1533 #endif | |
1534 | |
1535 if (buf == NULL) /* No previous buffer, Try 2'nd approach */ | |
1536 { | |
1537 forward = TRUE; | |
1538 buf = curbuf->b_next; | |
1539 for (;;) | |
1540 { | |
1541 if (buf == NULL) | |
1542 { | |
1543 if (!forward) /* tried both directions */ | |
1544 break; | |
1545 buf = curbuf->b_prev; | |
1546 forward = FALSE; | |
1547 continue; | |
1548 } | |
1549 /* in non-help buffer, try to skip help buffers, and vv */ | |
1550 if (buf->b_help == curbuf->b_help && buf->b_p_bl) | |
1551 { | |
1552 if (buf->b_ml.ml_mfp != NULL) /* found loaded buffer */ | |
1553 break; | |
1554 if (bp == NULL) /* remember unloaded buf for later */ | |
1555 bp = buf; | |
1556 } | |
1557 if (forward) | |
1558 buf = buf->b_next; | |
1559 else | |
1560 buf = buf->b_prev; | |
1561 } | |
1562 } | |
1563 if (buf == NULL) /* No loaded buffer, use unloaded one */ | |
1564 buf = bp; | |
1565 if (buf == NULL) /* No loaded buffer, find listed one */ | |
1566 { | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
1567 FOR_ALL_BUFFERS(buf) |
7 | 1568 if (buf->b_p_bl && buf != curbuf) |
1569 break; | |
1570 } | |
1571 if (buf == NULL) /* Still no buffer, just take one */ | |
1572 { | |
1573 if (curbuf->b_next != NULL) | |
1574 buf = curbuf->b_next; | |
1575 else | |
1576 buf = curbuf->b_prev; | |
1577 } | |
1578 } | |
1579 | |
5586 | 1580 if (buf == NULL) |
1581 { | |
1582 /* Autocommands must have wiped out all other buffers. Only option | |
1583 * now is to make the current buffer empty. */ | |
1584 return empty_curbuf(FALSE, forceit, action); | |
1585 } | |
1586 | |
7 | 1587 /* |
1588 * make buf current buffer | |
1589 */ | |
1590 if (action == DOBUF_SPLIT) /* split window first */ | |
1591 { | |
1618 | 1592 /* If 'switchbuf' contains "useopen": jump to first window containing |
1593 * "buf" if one exists */ | |
1594 if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf)) | |
825 | 1595 return OK; |
1736 | 1596 /* If 'switchbuf' contains "usetab": jump to first window in any tab |
1618 | 1597 * page containing "buf" if one exists */ |
1598 if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf)) | |
7 | 1599 return OK; |
1600 if (win_split(0, 0) == FAIL) | |
1601 return FAIL; | |
1602 } | |
1603 | |
1604 /* go to current buffer - nothing to do */ | |
1605 if (buf == curbuf) | |
1606 return OK; | |
1607 | |
1608 /* | |
1609 * Check if the current buffer may be abandoned. | |
1610 */ | |
1611 if (action == DOBUF_GOTO && !can_abandon(curbuf, forceit)) | |
1612 { | |
1613 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
1614 if ((p_confirm || cmdmod.confirm) && p_write) | |
1615 { | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1616 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1617 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1618 set_bufref(&bufref, buf); |
7 | 1619 dialog_changed(curbuf, FALSE); |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1620 if (!bufref_valid(&bufref)) |
7 | 1621 /* Autocommand deleted buffer, oops! */ |
1622 return FAIL; | |
1623 } | |
1624 if (bufIsChanged(curbuf)) | |
1625 #endif | |
1626 { | |
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
|
1627 no_write_message(); |
7 | 1628 return FAIL; |
1629 } | |
1630 } | |
1631 | |
1632 /* Go to the other buffer. */ | |
1633 set_curbuf(buf, action); | |
1634 | |
1635 if (action == DOBUF_SPLIT) | |
2583 | 1636 RESET_BINDING(curwin); /* reset 'scrollbind' and 'cursorbind' */ |
7 | 1637 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1638 #if defined(FEAT_EVAL) |
7 | 1639 if (aborting()) /* autocmds may abort script processing */ |
1640 return FAIL; | |
1641 #endif | |
1642 | |
1643 return OK; | |
1644 } | |
1645 | |
1646 /* | |
1647 * Set current buffer to "buf". Executes autocommands and closes current | |
1648 * buffer. "action" tells how to close the current buffer: | |
1649 * DOBUF_GOTO free or hide it | |
1650 * DOBUF_SPLIT nothing | |
1651 * DOBUF_UNLOAD unload it | |
1652 * DOBUF_DEL delete it | |
1653 * 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
|
1654 * DOBUF_WIPE_REUSE wipe it out and add to "buf_reuse" |
7 | 1655 */ |
1656 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1657 set_curbuf(buf_T *buf, int action) |
7 | 1658 { |
1659 buf_T *prevbuf; | |
1660 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
|
1661 || action == DOBUF_WIPE || action == DOBUF_WIPE_REUSE); |
4139 | 1662 #ifdef FEAT_SYN_HL |
1663 long old_tw = curbuf->b_p_tw; | |
1664 #endif | |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1665 bufref_T newbufref; |
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1666 bufref_T prevbufref; |
7 | 1667 |
1668 setpcmark(); | |
22 | 1669 if (!cmdmod.keepalt) |
1670 curwin->w_alt_fnum = curbuf->b_fnum; /* remember alternate file */ | |
1743 | 1671 buflist_altfpos(curwin); /* remember curpos */ |
7 | 1672 |
1673 /* Don't restart Select mode after switching to another buffer. */ | |
1674 VIsual_reselect = FALSE; | |
1675 | |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1676 /* close_windows() or apply_autocmds() may change curbuf and wipe out "buf" |
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1677 */ |
7 | 1678 prevbuf = curbuf; |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1679 set_bufref(&prevbufref, prevbuf); |
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1680 set_bufref(&newbufref, buf); |
7 | 1681 |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1682 /* Autocommands may delete the curren buffer and/or the buffer we wan to go |
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1683 * 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
|
1684 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
|
1685 || (bufref_valid(&prevbufref) |
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1686 && bufref_valid(&newbufref) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1687 #ifdef FEAT_EVAL |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1688 && !aborting() |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1689 #endif |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1690 )) |
7 | 1691 { |
3068 | 1692 #ifdef FEAT_SYN_HL |
1693 if (prevbuf == curwin->w_buffer) | |
1694 reset_synblock(curwin); | |
1695 #endif | |
7 | 1696 if (unload) |
671 | 1697 close_windows(prevbuf, FALSE); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1698 #if defined(FEAT_EVAL) |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1699 if (bufref_valid(&prevbufref) && !aborting()) |
7 | 1700 #else |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1701 if (bufref_valid(&prevbufref)) |
7 | 1702 #endif |
815 | 1703 { |
3654 | 1704 win_T *previouswin = curwin; |
815 | 1705 if (prevbuf == curbuf) |
825 | 1706 u_sync(FALSE); |
7 | 1707 close_buffer(prevbuf == curwin->w_buffer ? curwin : NULL, prevbuf, |
1708 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
|
1709 && !buf_hide(prevbuf) |
3365 | 1710 && !bufIsChanged(prevbuf)) ? DOBUF_UNLOAD : 0, FALSE); |
3654 | 1711 if (curwin != previouswin && win_valid(previouswin)) |
3594 | 1712 /* autocommands changed curwin, Grr! */ |
3654 | 1713 curwin = previouswin; |
815 | 1714 } |
7 | 1715 } |
1710 | 1716 /* An autocommand may have deleted "buf", already entered it (e.g., when |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1717 * it did ":bunload") or aborted the script processing. |
3594 | 1718 * If curwin->w_buffer is null, enter_buffer() will make it valid again */ |
1719 if ((buf_valid(buf) && buf != curbuf | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1720 #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
|
1721 && !aborting() |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1722 #endif |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
1723 ) || curwin->w_buffer == NULL) |
4139 | 1724 { |
7 | 1725 enter_buffer(buf); |
4139 | 1726 #ifdef FEAT_SYN_HL |
1727 if (old_tw != curbuf->b_p_tw) | |
1728 check_colorcolumn(curwin); | |
1729 #endif | |
1730 } | |
7 | 1731 } |
1732 | |
1733 /* | |
1734 * Enter a new current buffer. | |
4139 | 1735 * Old curbuf must have been abandoned already! This also means "curbuf" may |
1736 * be pointing to freed memory. | |
7 | 1737 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
1738 static void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1739 enter_buffer(buf_T *buf) |
7 | 1740 { |
18156
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
1741 // 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
|
1742 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
|
1743 curbuf = buf; |
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
1744 ++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
|
1745 |
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
1746 // Copy buffer and window local option values. Not for a help buffer. |
7 | 1747 buf_copy_options(buf, BCO_ENTER | BCO_NOHELP); |
1748 if (!buf->b_help) | |
1749 get_winopts(buf); | |
1750 #ifdef FEAT_FOLDING | |
1751 else | |
18156
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
1752 // Remove all folds in the window. |
7 | 1753 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
|
1754 foldUpdateAll(curwin); // update folds (later). |
7 | 1755 #endif |
1756 | |
1757 #ifdef FEAT_DIFF | |
672 | 1758 if (curwin->w_p_diff) |
1759 diff_buf_add(curbuf); | |
7 | 1760 #endif |
1761 | |
3068 | 1762 #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
|
1763 curwin->w_s = &(curbuf->b_s); |
3068 | 1764 #endif |
1765 | |
7 | 1766 /* Cursor on first line by default. */ |
1767 curwin->w_cursor.lnum = 1; | |
1768 curwin->w_cursor.col = 0; | |
1769 curwin->w_cursor.coladd = 0; | |
1770 curwin->w_set_curswant = TRUE; | |
1744 | 1771 curwin->w_topline_was_set = FALSE; |
7 | 1772 |
2091
95b659982b7c
updated for version 7.2.375
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1773 /* mark cursor position as being invalid */ |
95b659982b7c
updated for version 7.2.375
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1774 curwin->w_valid = 0; |
95b659982b7c
updated for version 7.2.375
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1775 |
14826
75d474a8868a
patch 8.1.0425: ml_get error and crash with appendbufline()
Christian Brabandt <cb@256bit.org>
parents:
14744
diff
changeset
|
1776 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
|
1777 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
|
1778 |
7 | 1779 /* Make sure the buffer is loaded. */ |
1780 if (curbuf->b_ml.ml_mfp == NULL) /* need to load the file */ | |
22 | 1781 { |
1782 /* If there is no filetype, allow for detecting one. Esp. useful for | |
1783 * ":ball" used in a autocommand. If there already is a filetype we | |
1784 * might prefer to keep it. */ | |
1785 if (*curbuf->b_p_ft == NUL) | |
1786 did_filetype = FALSE; | |
1787 | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
1788 open_buffer(FALSE, NULL, 0); |
22 | 1789 } |
7 | 1790 else |
1791 { | |
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
|
1792 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
|
1793 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
|
1794 |
ca1814eeecf5
patch 8.1.1334: when buffer is hidden "F" in 'shortmess' is not used
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
1795 // 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
|
1796 (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
|
1797 |
7 | 1798 curwin->w_topline = 1; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1799 #ifdef FEAT_DIFF |
7 | 1800 curwin->w_topfill = 0; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1801 #endif |
7 | 1802 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); |
1803 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); | |
1804 } | |
1805 | |
1806 /* If autocommands did not change the cursor position, restore cursor lnum | |
1807 * and possibly cursor col. */ | |
1808 if (curwin->w_cursor.lnum == 1 && inindent(0)) | |
1809 buflist_getfpos(); | |
1810 | |
1811 check_arg_idx(curwin); /* check for valid arg_idx */ | |
1812 #ifdef FEAT_TITLE | |
1813 maketitle(); | |
1814 #endif | |
1744 | 1815 /* when autocmds didn't change it */ |
1816 if (curwin->w_topline == 1 && !curwin->w_topline_was_set) | |
7 | 1817 scroll_cursor_halfway(FALSE); /* redisplay at correct position */ |
1818 | |
33 | 1819 #ifdef FEAT_NETBEANS_INTG |
1820 /* Send fileOpened event because we've changed buffers. */ | |
2210 | 1821 netbeans_file_activated(curbuf); |
33 | 1822 #endif |
1823 | |
961 | 1824 /* 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
|
1825 DO_AUTOCHDIR; |
7 | 1826 |
1827 #ifdef FEAT_KEYMAP | |
1828 if (curbuf->b_kmap_state & KEYMAP_INIT) | |
1869 | 1829 (void)keymap_init(); |
7 | 1830 #endif |
1185 | 1831 #ifdef FEAT_SPELL |
1832 /* May need to set the spell language. Can only do this after the buffer | |
1833 * has been properly setup. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
1834 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
|
1835 (void)did_set_spelllang(curwin); |
1185 | 1836 #endif |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1837 #ifdef FEAT_VIMINFO |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1838 curbuf->b_last_used = vim_time(); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1839 #endif |
1185 | 1840 |
7 | 1841 redraw_later(NOT_VALID); |
1842 } | |
1843 | |
961 | 1844 #if defined(FEAT_AUTOCHDIR) || defined(PROTO) |
1845 /* | |
1846 * 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
|
1847 * Don't do this while still starting up. |
961 | 1848 */ |
1849 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1850 do_autochdir(void) |
961 | 1851 { |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9450
diff
changeset
|
1852 if ((starting == 0 || test_autochdir) |
8216
03af9acbefb0
commit https://github.com/vim/vim/commit/6bd364e08461159ad3c153ffba4def5b896486a1
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
1853 && curbuf->b_ffname != NULL |
13170
6559e98f3e74
patch 8.0.1459: cannot handle change of directory
Christian Brabandt <cb@256bit.org>
parents:
13121
diff
changeset
|
1854 && vim_chdirfile(curbuf->b_ffname, "auto") == OK) |
961 | 1855 shorten_fnames(TRUE); |
1856 } | |
1857 #endif | |
1858 | |
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
|
1859 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
|
1860 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
|
1861 { |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1862 #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
|
1863 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
|
1864 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
|
1865 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
|
1866 #endif |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1867 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
|
1868 } |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1869 |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1870 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
|
1871 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
|
1872 { |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1873 #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
|
1874 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
|
1875 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
|
1876 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
|
1877 #endif |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1878 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
|
1879 } |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1880 |
7 | 1881 /* |
1882 * functions for dealing with the buffer list | |
1883 */ | |
1884 | |
1885 /* | |
13782
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1886 * 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
|
1887 * 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
|
1888 */ |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1889 int |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1890 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
|
1891 { |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1892 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
|
1893 && 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
|
1894 && 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
|
1895 && (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
|
1896 #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
|
1897 && !bt_quickfix(curbuf) |
16261
2001ef982570
patch 8.1.1135: build failure for small version
Bram Moolenaar <Bram@vim.org>
parents:
16259
diff
changeset
|
1898 #endif |
13782
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1899 && !curbufIsChanged()); |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1900 } |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1901 |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1902 /* |
7 | 1903 * Add a file name to the buffer list. Return a pointer to the buffer. |
1904 * If the same file name already exists return a pointer to that buffer. | |
1905 * If it does not exist, or if fname == NULL, a new entry is created. | |
1906 * If (flags & BLN_CURBUF) is TRUE, may use current buffer. | |
1907 * If (flags & BLN_LISTED) is TRUE, add new buffer to buffer list. | |
1908 * 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
|
1909 * 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
|
1910 * 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
|
1911 * 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
|
1912 * If (flags & BLN_REUSE) is TRUE, may use buffer number from "buf_reuse". |
7 | 1913 * This is the ONLY way to create a new buffer. |
1914 */ | |
1915 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1916 buflist_new( |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1917 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
|
1918 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
|
1919 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
|
1920 int flags) // BLN_ defines |
7 | 1921 { |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1922 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
|
1923 char_u *sfname = sfname_arg; |
7 | 1924 buf_T *buf; |
1925 #ifdef UNIX | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
1926 stat_T st; |
7 | 1927 #endif |
1928 | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1929 if (top_file_num == 1) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1930 hash_init(&buf_hashtab); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1931 |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1932 fname_expand(curbuf, &ffname, &sfname); // will allocate ffname |
7 | 1933 |
1934 /* | |
1935 * If file name already exists in the list, update the entry. | |
1936 */ | |
1937 #ifdef UNIX | |
1938 /* On Unix we can use inode numbers when the file exists. Works better | |
1939 * for hard links. */ | |
1940 if (sfname == NULL || mch_stat((char *)sfname, &st) < 0) | |
1941 st.st_dev = (dev_T)-1; | |
1942 #endif | |
9149
18bbf31015c2
commit https://github.com/vim/vim/commit/b127cfd75f59e82580df395b6e2c009774644b16
Christian Brabandt <cb@256bit.org>
parents:
9106
diff
changeset
|
1943 if (ffname != NULL && !(flags & (BLN_DUMMY | BLN_NEW)) && (buf = |
7 | 1944 #ifdef UNIX |
1945 buflist_findname_stat(ffname, &st) | |
1946 #else | |
1947 buflist_findname(ffname) | |
1948 #endif | |
1949 ) != NULL) | |
1950 { | |
1951 vim_free(ffname); | |
1952 if (lnum != 0) | |
1953 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
|
1954 |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1955 if ((flags & BLN_NOOPT) == 0) |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1956 /* copy the options now, if 'cpo' doesn't have 's' and not done |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1957 * already */ |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1958 buf_copy_options(buf, 0); |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1959 |
7 | 1960 if ((flags & BLN_LISTED) && !buf->b_p_bl) |
1961 { | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1962 bufref_T bufref; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1963 |
7 | 1964 buf->b_p_bl = TRUE; |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1965 set_bufref(&bufref, buf); |
7 | 1966 if (!(flags & BLN_DUMMY)) |
5816 | 1967 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1968 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
|
1969 && !bufref_valid(&bufref)) |
5816 | 1970 return NULL; |
1971 } | |
7 | 1972 } |
1973 return buf; | |
1974 } | |
1975 | |
1976 /* | |
1977 * If the current buffer has no name and no contents, use the current | |
1978 * buffer. Otherwise: Need to allocate a new buffer structure. | |
1979 * | |
1980 * This is the ONLY place where a new buffer structure is allocated! | |
625 | 1981 * (A spell file buffer is allocated in spell.c, but that's not a normal |
1982 * buffer.) | |
7 | 1983 */ |
1984 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
|
1985 if ((flags & BLN_CURBUF) && curbuf_reusable()) |
7 | 1986 { |
1987 buf = curbuf; | |
1988 /* It's like this buffer is deleted. Watch out for autocommands that | |
1989 * change curbuf! If that happens, allocate a new buffer anyway. */ | |
1990 if (curbuf->b_p_bl) | |
1991 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); | |
1992 if (buf == curbuf) | |
1993 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
|
1994 #ifdef FEAT_EVAL |
36 | 1995 if (aborting()) /* autocmds may abort script processing */ |
7 | 1996 return NULL; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1997 #endif |
7 | 1998 if (buf == curbuf) |
1999 { | |
2000 /* Make sure 'bufhidden' and 'buftype' are empty */ | |
2001 clear_string_option(&buf->b_p_bh); | |
2002 clear_string_option(&buf->b_p_bt); | |
2003 } | |
2004 } | |
2005 if (buf != curbuf || curbuf == NULL) | |
2006 { | |
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
|
2007 buf = ALLOC_CLEAR_ONE(buf_T); |
7 | 2008 if (buf == NULL) |
2009 { | |
2010 vim_free(ffname); | |
2011 return NULL; | |
2012 } | |
4287 | 2013 #ifdef FEAT_EVAL |
2014 /* init b: variables */ | |
2015 buf->b_vars = dict_alloc(); | |
2016 if (buf->b_vars == NULL) | |
2017 { | |
2018 vim_free(ffname); | |
2019 vim_free(buf); | |
2020 return NULL; | |
2021 } | |
2022 init_var_dict(buf->b_vars, &buf->b_bufvar, VAR_SCOPE); | |
2023 #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
|
2024 init_changedtick(buf); |
7 | 2025 } |
2026 | |
2027 if (ffname != NULL) | |
2028 { | |
2029 buf->b_ffname = ffname; | |
2030 buf->b_sfname = vim_strsave(sfname); | |
2031 } | |
2032 | |
2033 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
|
2034 buf->b_wininfo = ALLOC_CLEAR_ONE(wininfo_T); |
7 | 2035 |
2036 if ((ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL)) | |
2037 || buf->b_wininfo == NULL) | |
2038 { | |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2039 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
|
2040 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
|
2041 else |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2042 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
|
2043 VIM_CLEAR(buf->b_ffname); |
7 | 2044 if (buf != curbuf) |
2045 free_buffer(buf); | |
2046 return NULL; | |
2047 } | |
2048 | |
2049 if (buf == curbuf) | |
2050 { | |
2051 /* 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
|
2052 buf_freeall(buf, 0); |
7 | 2053 if (buf != curbuf) /* autocommands deleted the buffer! */ |
2054 return NULL; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2055 #if defined(FEAT_EVAL) |
36 | 2056 if (aborting()) /* autocmds may abort script processing */ |
7 | 2057 return NULL; |
2058 #endif | |
2059 free_buffer_stuff(buf, FALSE); /* delete local variables et al. */ | |
3925 | 2060 |
2061 /* Init the options. */ | |
2062 buf->b_p_initialized = FALSE; | |
2063 buf_copy_options(buf, BCO_ENTER); | |
2064 | |
7 | 2065 #ifdef FEAT_KEYMAP |
2066 /* need to reload lmaps and set b:keymap_name */ | |
2067 curbuf->b_kmap_state |= KEYMAP_INIT; | |
2068 #endif | |
2069 } | |
2070 else | |
2071 { | |
2072 /* | |
2073 * put new buffer at the end of the buffer list | |
2074 */ | |
2075 buf->b_next = NULL; | |
2076 if (firstbuf == NULL) /* buffer list is empty */ | |
2077 { | |
2078 buf->b_prev = NULL; | |
2079 firstbuf = buf; | |
2080 } | |
2081 else /* append new buffer at end of list */ | |
2082 { | |
2083 lastbuf->b_next = buf; | |
2084 buf->b_prev = lastbuf; | |
2085 } | |
2086 lastbuf = buf; | |
2087 | |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2088 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
|
2089 { |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2090 // 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
|
2091 // 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
|
2092 // 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
|
2093 --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
|
2094 buf->b_fnum = ((int *)buf_reuse.ga_data)[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
|
2095 } |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2096 else |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2097 buf->b_fnum = top_file_num++; |
7 | 2098 if (top_file_num < 0) /* wrap around (may cause duplicates) */ |
2099 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
2100 emsg(_("W14: Warning: List of file names overflow")); |
7 | 2101 if (emsg_silent == 0) |
2102 { | |
2103 out_flush(); | |
2104 ui_delay(3000L, TRUE); /* make sure it is noticed */ | |
2105 } | |
2106 top_file_num = 1; | |
2107 } | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2108 buf_hashtab_add(buf); |
7 | 2109 |
2110 /* | |
2111 * Always copy the options from the current buffer. | |
2112 */ | |
2113 buf_copy_options(buf, BCO_ALWAYS); | |
2114 } | |
2115 | |
2116 buf->b_wininfo->wi_fpos.lnum = lnum; | |
2117 buf->b_wininfo->wi_win = curwin; | |
2118 | |
126 | 2119 #ifdef FEAT_SYN_HL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2120 hash_init(&buf->b_s.b_keywtab); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2121 hash_init(&buf->b_s.b_keywtab_ic); |
7 | 2122 #endif |
2123 | |
2124 buf->b_fname = buf->b_sfname; | |
2125 #ifdef UNIX | |
2126 if (st.st_dev == (dev_T)-1) | |
1873 | 2127 buf->b_dev_valid = FALSE; |
7 | 2128 else |
2129 { | |
1873 | 2130 buf->b_dev_valid = TRUE; |
7 | 2131 buf->b_dev = st.st_dev; |
2132 buf->b_ino = st.st_ino; | |
2133 } | |
2134 #endif | |
2135 buf->b_u_synced = TRUE; | |
2136 buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED; | |
42 | 2137 if (flags & BLN_DUMMY) |
2138 buf->b_flags |= BF_DUMMY; | |
7 | 2139 buf_clear_file(buf); |
2140 clrallmarks(buf); /* clear marks */ | |
2141 fmarks_check_names(buf); /* check file marks for this file */ | |
2142 buf->b_p_bl = (flags & BLN_LISTED) ? TRUE : FALSE; /* init 'buflisted' */ | |
2143 if (!(flags & BLN_DUMMY)) | |
2144 { | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
2145 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
2146 |
6639 | 2147 /* Tricky: these autocommands may change the buffer list. They could |
2148 * also split the window with re-using the one empty buffer. This may | |
2149 * 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
|
2150 set_bufref(&bufref, buf); |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
2151 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
|
2152 && !bufref_valid(&bufref)) |
5816 | 2153 return NULL; |
7 | 2154 if (flags & BLN_LISTED) |
5816 | 2155 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
2156 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
|
2157 && !bufref_valid(&bufref)) |
5816 | 2158 return NULL; |
2159 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2160 #ifdef FEAT_EVAL |
36 | 2161 if (aborting()) /* autocmds may abort script processing */ |
7 | 2162 return NULL; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2163 #endif |
7 | 2164 } |
2165 | |
2166 return buf; | |
2167 } | |
2168 | |
2169 /* | |
2170 * Free the memory for the options of a buffer. | |
2171 * If "free_p_ff" is TRUE also free 'fileformat', 'buftype' and | |
2172 * 'fileencoding'. | |
2173 */ | |
2174 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2175 free_buf_options( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2176 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2177 int free_p_ff) |
7 | 2178 { |
2179 if (free_p_ff) | |
2180 { | |
2181 clear_string_option(&buf->b_p_fenc); | |
2182 clear_string_option(&buf->b_p_ff); | |
2183 clear_string_option(&buf->b_p_bh); | |
2184 clear_string_option(&buf->b_p_bt); | |
2185 } | |
2186 #ifdef FEAT_FIND_ID | |
2187 clear_string_option(&buf->b_p_def); | |
2188 clear_string_option(&buf->b_p_inc); | |
2189 # ifdef FEAT_EVAL | |
2190 clear_string_option(&buf->b_p_inex); | |
2191 # endif | |
2192 #endif | |
2193 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) | |
2194 clear_string_option(&buf->b_p_inde); | |
2195 clear_string_option(&buf->b_p_indk); | |
2196 #endif | |
788 | 2197 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
2198 clear_string_option(&buf->b_p_bexpr); | |
2199 #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
|
2200 #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
|
2201 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
|
2202 #endif |
10678
c647f01d6dbd
patch 8.0.0229: local 'formatprg' option value leaks
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
2203 clear_string_option(&buf->b_p_fp); |
667 | 2204 #if defined(FEAT_EVAL) |
2205 clear_string_option(&buf->b_p_fex); | |
2206 #endif | |
7 | 2207 #ifdef FEAT_CRYPT |
2208 clear_string_option(&buf->b_p_key); | |
2209 #endif | |
2210 clear_string_option(&buf->b_p_kp); | |
2211 clear_string_option(&buf->b_p_mps); | |
2212 clear_string_option(&buf->b_p_fo); | |
41 | 2213 clear_string_option(&buf->b_p_flp); |
7 | 2214 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
|
2215 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
2216 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
|
2217 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
|
2218 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
|
2219 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
|
2220 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
|
2221 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
|
2222 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
|
2223 #endif |
7 | 2224 #ifdef FEAT_KEYMAP |
2225 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
|
2226 keymap_clear(&buf->b_kmap_ga); |
7 | 2227 ga_clear(&buf->b_kmap_ga); |
2228 #endif | |
2229 clear_string_option(&buf->b_p_com); | |
2230 #ifdef FEAT_FOLDING | |
2231 clear_string_option(&buf->b_p_cms); | |
2232 #endif | |
2233 clear_string_option(&buf->b_p_nf); | |
2234 #ifdef FEAT_SYN_HL | |
2235 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
|
2236 clear_string_option(&buf->b_s.b_syn_isk); |
737 | 2237 #endif |
2238 #ifdef FEAT_SPELL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2239 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
|
2240 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
|
2241 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
|
2242 buf->b_s.b_cap_prog = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2243 clear_string_option(&buf->b_s.b_p_spl); |
7 | 2244 #endif |
2245 #ifdef FEAT_SEARCHPATH | |
2246 clear_string_option(&buf->b_p_sua); | |
2247 #endif | |
2248 clear_string_option(&buf->b_p_ft); | |
2249 #ifdef FEAT_CINDENT | |
2250 clear_string_option(&buf->b_p_cink); | |
2251 clear_string_option(&buf->b_p_cino); | |
2252 #endif | |
2253 #if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT) | |
2254 clear_string_option(&buf->b_p_cinw); | |
2255 #endif | |
2256 clear_string_option(&buf->b_p_cpt); | |
12 | 2257 #ifdef FEAT_COMPL_FUNC |
2258 clear_string_option(&buf->b_p_cfu); | |
502 | 2259 clear_string_option(&buf->b_p_ofu); |
12 | 2260 #endif |
7 | 2261 #ifdef FEAT_QUICKFIX |
2262 clear_string_option(&buf->b_p_gp); | |
2263 clear_string_option(&buf->b_p_mp); | |
2264 clear_string_option(&buf->b_p_efm); | |
2265 #endif | |
2266 clear_string_option(&buf->b_p_ep); | |
2267 clear_string_option(&buf->b_p_path); | |
2268 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
|
2269 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
|
2270 #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
|
2271 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
|
2272 #endif |
7 | 2273 clear_string_option(&buf->b_p_dict); |
2274 clear_string_option(&buf->b_p_tsr); | |
12 | 2275 #ifdef FEAT_TEXTOBJ |
2276 clear_string_option(&buf->b_p_qe); | |
2277 #endif | |
7 | 2278 buf->b_p_ar = -1; |
5446 | 2279 buf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
5712 | 2280 #ifdef FEAT_LISP |
2281 clear_string_option(&buf->b_p_lw); | |
2282 #endif | |
6243 | 2283 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
|
2284 clear_string_option(&buf->b_p_menc); |
7 | 2285 } |
2286 | |
2287 /* | |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2288 * 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
|
2289 * 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
|
2290 * Also set cursor column to altfpos.col if 'startofline' is not set. |
7 | 2291 * if (options & GETF_SETMARK) call setpcmark() |
2292 * if (options & GETF_ALT) we are jumping to an alternate file. | |
2293 * if (options & GETF_SWITCH) respect 'switchbuf' settings when jumping | |
2294 * | |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2295 * Return FAIL for failure, OK for success. |
7 | 2296 */ |
2297 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2298 buflist_getfile( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2299 int n, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2300 linenr_T lnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2301 int options, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2302 int forceit) |
7 | 2303 { |
2304 buf_T *buf; | |
2305 win_T *wp = NULL; | |
2306 pos_T *fpos; | |
2307 colnr_T col; | |
2308 | |
2309 buf = buflist_findnr(n); | |
2310 if (buf == NULL) | |
2311 { | |
2312 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
|
2313 emsg(_(e_noalt)); |
7 | 2314 else |
15490
98c35d312987
patch 8.1.0753: printf format not checked for semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
2315 semsg(_("E92: Buffer %d not found"), n); |
7 | 2316 return FAIL; |
2317 } | |
2318 | |
2319 /* if alternate file is the current buffer, nothing to do */ | |
2320 if (buf == curbuf) | |
2321 return OK; | |
2322 | |
633 | 2323 if (text_locked()) |
631 | 2324 { |
633 | 2325 text_locked_msg(); |
7 | 2326 return FAIL; |
631 | 2327 } |
819 | 2328 if (curbuf_locked()) |
2329 return FAIL; | |
7 | 2330 |
2331 /* altfpos may be changed by getfile(), get it now */ | |
2332 if (lnum == 0) | |
2333 { | |
2334 fpos = buflist_findfpos(buf); | |
2335 lnum = fpos->lnum; | |
2336 col = fpos->col; | |
2337 } | |
2338 else | |
2339 col = 0; | |
2340 | |
2341 if (options & GETF_SWITCH) | |
2342 { | |
1618 | 2343 /* If 'switchbuf' contains "useopen": jump to first window containing |
2344 * "buf" if one exists */ | |
2345 if (swb_flags & SWB_USEOPEN) | |
7 | 2346 wp = buf_jump_open_win(buf); |
6843 | 2347 |
4352 | 2348 /* If 'switchbuf' contains "usetab": jump to first window in any tab |
1618 | 2349 * page containing "buf" if one exists */ |
2350 if (wp == NULL && (swb_flags & SWB_USETAB)) | |
825 | 2351 wp = buf_jump_open_tab(buf); |
6843 | 2352 |
2353 /* If 'switchbuf' contains "split", "vsplit" or "newtab" and the | |
2354 * current buffer isn't empty: open new tab or window */ | |
2355 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
|
2356 && !BUFEMPTY()) |
7 | 2357 { |
6843 | 2358 if (swb_flags & SWB_NEWTAB) |
1618 | 2359 tabpage_new(); |
6843 | 2360 else if (win_split(0, (swb_flags & SWB_VSPLIT) ? WSP_VERT : 0) |
2361 == FAIL) | |
7 | 2362 return FAIL; |
2583 | 2363 RESET_BINDING(curwin); |
7 | 2364 } |
2365 } | |
2366 | |
2367 ++RedrawingDisabled; | |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11447
diff
changeset
|
2368 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
|
2369 (options & GETF_SETMARK), lnum, forceit))) |
7 | 2370 { |
2371 --RedrawingDisabled; | |
2372 | |
2373 /* cursor is at to BOL and w_cursor.lnum is checked due to getfile() */ | |
2374 if (!p_sol && col != 0) | |
2375 { | |
2376 curwin->w_cursor.col = col; | |
2377 check_cursor_col(); | |
2378 curwin->w_cursor.coladd = 0; | |
2379 curwin->w_set_curswant = TRUE; | |
2380 } | |
2381 return OK; | |
2382 } | |
2383 --RedrawingDisabled; | |
2384 return FAIL; | |
2385 } | |
2386 | |
2387 /* | |
2388 * go to the last know line number for the current buffer | |
2389 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2390 static void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2391 buflist_getfpos(void) |
7 | 2392 { |
2393 pos_T *fpos; | |
2394 | |
2395 fpos = buflist_findfpos(curbuf); | |
2396 | |
2397 curwin->w_cursor.lnum = fpos->lnum; | |
2398 check_cursor_lnum(); | |
2399 | |
2400 if (p_sol) | |
2401 curwin->w_cursor.col = 0; | |
2402 else | |
2403 { | |
2404 curwin->w_cursor.col = fpos->col; | |
2405 check_cursor_col(); | |
2406 curwin->w_cursor.coladd = 0; | |
2407 curwin->w_set_curswant = TRUE; | |
2408 } | |
2409 } | |
2410 | |
42 | 2411 #if defined(FEAT_QUICKFIX) || defined(FEAT_EVAL) || defined(PROTO) |
2412 /* | |
2413 * Find file in buffer list by name (it has to be for the current window). | |
2414 * Returns NULL if not found. | |
2415 */ | |
2416 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2417 buflist_findname_exp(char_u *fname) |
42 | 2418 { |
2419 char_u *ffname; | |
2420 buf_T *buf = NULL; | |
2421 | |
2422 /* First make the name into a full path name */ | |
2423 ffname = FullName_save(fname, | |
2424 #ifdef UNIX | |
2425 TRUE /* force expansion, get rid of symbolic links */ | |
2426 #else | |
2427 FALSE | |
2428 #endif | |
2429 ); | |
2430 if (ffname != NULL) | |
2431 { | |
2432 buf = buflist_findname(ffname); | |
2433 vim_free(ffname); | |
2434 } | |
2435 return buf; | |
2436 } | |
2437 #endif | |
2438 | |
7 | 2439 /* |
2440 * Find file in buffer list by name (it has to be for the current window). | |
2441 * "ffname" must have a full path. | |
42 | 2442 * Skips dummy buffers. |
2443 * Returns NULL if not found. | |
7 | 2444 */ |
2445 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2446 buflist_findname(char_u *ffname) |
7 | 2447 { |
2448 #ifdef UNIX | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
2449 stat_T st; |
7 | 2450 |
2451 if (mch_stat((char *)ffname, &st) < 0) | |
2452 st.st_dev = (dev_T)-1; | |
2453 return buflist_findname_stat(ffname, &st); | |
2454 } | |
2455 | |
2456 /* | |
2457 * Same as buflist_findname(), but pass the stat structure to avoid getting it | |
2458 * twice for the same file. | |
42 | 2459 * Returns NULL if not found. |
7 | 2460 */ |
2461 static buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2462 buflist_findname_stat( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2463 char_u *ffname, |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
2464 stat_T *stp) |
7 | 2465 { |
2466 #endif | |
2467 buf_T *buf; | |
2468 | |
9485
c16e207dc465
commit https://github.com/vim/vim/commit/ea3f2e7be447a8f0c4436869620f908de5e8ef1e
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
2469 /* Start at the last buffer, expect to find a match sooner. */ |
c16e207dc465
commit https://github.com/vim/vim/commit/ea3f2e7be447a8f0c4436869620f908de5e8ef1e
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
2470 for (buf = lastbuf; buf != NULL; buf = buf->b_prev) |
42 | 2471 if ((buf->b_flags & BF_DUMMY) == 0 && !otherfile_buf(buf, ffname |
7 | 2472 #ifdef UNIX |
2473 , stp | |
2474 #endif | |
2475 )) | |
2476 return buf; | |
2477 return NULL; | |
2478 } | |
2479 | |
2480 /* | |
2481 * Find file in buffer list by a regexp pattern. | |
2482 * Return fnum of the found buffer. | |
2483 * Return < 0 for error. | |
2484 */ | |
2485 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2486 buflist_findpat( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2487 char_u *pattern, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2488 char_u *pattern_end, /* pointer to first char after pattern */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2489 int unlisted, /* find unlisted buffers */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2490 int diffmode UNUSED, /* find diff-mode buffers only */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2491 int curtab_only) /* find buffers in current tab only */ |
7 | 2492 { |
2493 buf_T *buf; | |
2494 int match = -1; | |
2495 int find_listed; | |
2496 char_u *pat; | |
2497 char_u *patend; | |
2498 int attempt; | |
2499 char_u *p; | |
2500 int toggledollar; | |
2501 | |
2502 if (pattern_end == pattern + 1 && (*pattern == '%' || *pattern == '#')) | |
2503 { | |
2504 if (*pattern == '%') | |
2505 match = curbuf->b_fnum; | |
2506 else | |
2507 match = curwin->w_alt_fnum; | |
2508 #ifdef FEAT_DIFF | |
2509 if (diffmode && !diff_mode_buf(buflist_findnr(match))) | |
2510 match = -1; | |
2511 #endif | |
2512 } | |
2513 | |
2514 /* | |
2515 * Try four ways of matching a listed buffer: | |
2516 * attempt == 0: without '^' or '$' (at any position) | |
1187 | 2517 * attempt == 1: with '^' at start (only at position 0) |
7 | 2518 * attempt == 2: with '$' at end (only match at end) |
2519 * attempt == 3: with '^' at start and '$' at end (only full match) | |
2520 * Repeat this for finding an unlisted buffer if there was no matching | |
2521 * listed buffer. | |
2522 */ | |
2523 else | |
2524 { | |
2525 pat = file_pat_to_reg_pat(pattern, pattern_end, NULL, FALSE); | |
2526 if (pat == NULL) | |
2527 return -1; | |
2528 patend = pat + STRLEN(pat) - 1; | |
2529 toggledollar = (patend > pat && *patend == '$'); | |
2530 | |
2531 /* First try finding a listed buffer. If not found and "unlisted" | |
2532 * is TRUE, try finding an unlisted buffer. */ | |
2533 find_listed = TRUE; | |
2534 for (;;) | |
2535 { | |
2536 for (attempt = 0; attempt <= 3; ++attempt) | |
2537 { | |
6375 | 2538 regmatch_T regmatch; |
2539 | |
7 | 2540 /* may add '^' and '$' */ |
2541 if (toggledollar) | |
2542 *patend = (attempt < 2) ? NUL : '$'; /* add/remove '$' */ | |
2543 p = pat; | |
2544 if (*p == '^' && !(attempt & 1)) /* add/remove '^' */ | |
2545 ++p; | |
6375 | 2546 regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); |
2547 if (regmatch.regprog == NULL) | |
7 | 2548 { |
2549 vim_free(pat); | |
2550 return -1; | |
2551 } | |
2552 | |
9485
c16e207dc465
commit https://github.com/vim/vim/commit/ea3f2e7be447a8f0c4436869620f908de5e8ef1e
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
2553 for (buf = lastbuf; buf != NULL; buf = buf->b_prev) |
7 | 2554 if (buf->b_p_bl == find_listed |
2555 #ifdef FEAT_DIFF | |
2556 && (!diffmode || diff_mode_buf(buf)) | |
2557 #endif | |
6375 | 2558 && buflist_match(®match, buf, FALSE) != NULL) |
7 | 2559 { |
4236 | 2560 if (curtab_only) |
2561 { | |
2562 /* Ignore the match if the buffer is not open in | |
2563 * the current tab. */ | |
2564 win_T *wp; | |
2565 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
2566 FOR_ALL_WINDOWS(wp) |
4236 | 2567 if (wp->w_buffer == buf) |
2568 break; | |
2569 if (wp == NULL) | |
2570 continue; | |
2571 } | |
7 | 2572 if (match >= 0) /* already found a match */ |
2573 { | |
2574 match = -2; | |
2575 break; | |
2576 } | |
2577 match = buf->b_fnum; /* remember first match */ | |
2578 } | |
2579 | |
6375 | 2580 vim_regfree(regmatch.regprog); |
7 | 2581 if (match >= 0) /* found one match */ |
2582 break; | |
2583 } | |
2584 | |
2585 /* Only search for unlisted buffers if there was no match with | |
2586 * a listed buffer. */ | |
2587 if (!unlisted || !find_listed || match != -1) | |
2588 break; | |
2589 find_listed = FALSE; | |
2590 } | |
2591 | |
2592 vim_free(pat); | |
2593 } | |
2594 | |
2595 if (match == -2) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
2596 semsg(_("E93: More than one match for %s"), pattern); |
7 | 2597 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
|
2598 semsg(_("E94: No matching buffer for %s"), pattern); |
7 | 2599 return match; |
2600 } | |
2601 | |
2602 /* | |
2603 * Find all buffer names that match. | |
2604 * For command line expansion of ":buf" and ":sbuf". | |
2605 * Return OK if matches found, FAIL otherwise. | |
2606 */ | |
2607 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2608 ExpandBufnames( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2609 char_u *pat, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2610 int *num_file, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2611 char_u ***file, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2612 int options) |
7 | 2613 { |
2614 int count = 0; | |
2615 buf_T *buf; | |
2616 int round; | |
2617 char_u *p; | |
2618 int attempt; | |
170 | 2619 char_u *patc; |
7 | 2620 |
2621 *num_file = 0; /* return values in case of FAIL */ | |
2622 *file = NULL; | |
2623 | |
170 | 2624 /* Make a copy of "pat" and change "^" to "\(^\|[\/]\)". */ |
2625 if (*pat == '^') | |
2626 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16740
diff
changeset
|
2627 patc = alloc(STRLEN(pat) + 11); |
170 | 2628 if (patc == NULL) |
2629 return FAIL; | |
2630 STRCPY(patc, "\\(^\\|[\\/]\\)"); | |
2631 STRCPY(patc + 11, pat + 1); | |
2632 } | |
2633 else | |
2634 patc = pat; | |
2635 | |
7 | 2636 /* |
170 | 2637 * attempt == 0: try match with '\<', match at start of word |
267 | 2638 * attempt == 1: try match without '\<', match anywhere |
7 | 2639 */ |
267 | 2640 for (attempt = 0; attempt <= 1; ++attempt) |
7 | 2641 { |
6375 | 2642 regmatch_T regmatch; |
2643 | |
267 | 2644 if (attempt > 0 && patc == pat) |
170 | 2645 break; /* there was no anchor, no need to try again */ |
6375 | 2646 regmatch.regprog = vim_regcomp(patc + attempt * 11, RE_MAGIC); |
2647 if (regmatch.regprog == NULL) | |
7 | 2648 { |
170 | 2649 if (patc != pat) |
2650 vim_free(patc); | |
2651 return FAIL; | |
7 | 2652 } |
2653 | |
2654 /* | |
2655 * round == 1: Count the matches. | |
2656 * round == 2: Build the array to keep the matches. | |
2657 */ | |
2658 for (round = 1; round <= 2; ++round) | |
2659 { | |
2660 count = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
2661 FOR_ALL_BUFFERS(buf) |
7 | 2662 { |
2663 if (!buf->b_p_bl) /* skip unlisted buffers */ | |
2664 continue; | |
6375 | 2665 p = buflist_match(®match, buf, p_wic); |
7 | 2666 if (p != NULL) |
2667 { | |
2668 if (round == 1) | |
2669 ++count; | |
2670 else | |
2671 { | |
2672 if (options & WILD_HOME_REPLACE) | |
2673 p = home_replace_save(buf, p); | |
2674 else | |
2675 p = vim_strsave(p); | |
2676 (*file)[count++] = p; | |
2677 } | |
2678 } | |
2679 } | |
2680 if (count == 0) /* no match found, break here */ | |
2681 break; | |
2682 if (round == 1) | |
2683 { | |
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
|
2684 *file = ALLOC_MULT(char_u *, count); |
7 | 2685 if (*file == NULL) |
2686 { | |
6375 | 2687 vim_regfree(regmatch.regprog); |
170 | 2688 if (patc != pat) |
2689 vim_free(patc); | |
7 | 2690 return FAIL; |
2691 } | |
2692 } | |
2693 } | |
6375 | 2694 vim_regfree(regmatch.regprog); |
7 | 2695 if (count) /* match(es) found, break here */ |
2696 break; | |
2697 } | |
2698 | |
170 | 2699 if (patc != pat) |
2700 vim_free(patc); | |
2701 | |
7 | 2702 *num_file = count; |
2703 return (count == 0 ? FAIL : OK); | |
2704 } | |
2705 | |
2706 /* | |
2707 * Check for a match on the file name for buffer "buf" with regprog "prog". | |
2708 */ | |
2709 static char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2710 buflist_match( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2711 regmatch_T *rmp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2712 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2713 int ignore_case) /* when TRUE ignore case, when FALSE use 'fic' */ |
7 | 2714 { |
2715 char_u *match; | |
2716 | |
2717 /* First try the short file name, then the long file name. */ | |
6375 | 2718 match = fname_match(rmp, buf->b_sfname, ignore_case); |
7 | 2719 if (match == NULL) |
6375 | 2720 match = fname_match(rmp, buf->b_ffname, ignore_case); |
7 | 2721 |
2722 return match; | |
2723 } | |
2724 | |
2725 /* | |
2726 * Try matching the regexp in "prog" with file name "name". | |
2727 * Return "name" when there is a match, NULL when not. | |
2728 */ | |
2729 static char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2730 fname_match( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2731 regmatch_T *rmp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2732 char_u *name, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2733 int ignore_case) /* when TRUE ignore case, when FALSE use 'fic' */ |
7 | 2734 { |
2735 char_u *match = NULL; | |
2736 char_u *p; | |
2737 | |
2738 if (name != NULL) | |
2739 { | |
6241 | 2740 /* Ignore case when 'fileignorecase' or the argument is set. */ |
6375 | 2741 rmp->rm_ic = p_fic || ignore_case; |
2742 if (vim_regexec(rmp, name, (colnr_T)0)) | |
7 | 2743 match = name; |
2744 else | |
2745 { | |
2746 /* Replace $(HOME) with '~' and try matching again. */ | |
2747 p = home_replace_save(NULL, name); | |
6375 | 2748 if (p != NULL && vim_regexec(rmp, p, (colnr_T)0)) |
7 | 2749 match = name; |
2750 vim_free(p); | |
2751 } | |
2752 } | |
2753 | |
2754 return match; | |
2755 } | |
2756 | |
2757 /* | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2758 * Find a file in the buffer list by buffer number. |
7 | 2759 */ |
2760 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2761 buflist_findnr(int nr) |
7 | 2762 { |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2763 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
|
2764 hashitem_T *hi; |
7 | 2765 |
2766 if (nr == 0) | |
2767 nr = curwin->w_alt_fnum; | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2768 sprintf((char *)key, "%x", nr); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2769 hi = hash_find(&buf_hashtab, key); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2770 |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2771 if (!HASHITEM_EMPTY(hi)) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2772 return (buf_T *)(hi->hi_key |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2773 - ((unsigned)(curbuf->b_key - (char_u *)curbuf))); |
7 | 2774 return NULL; |
2775 } | |
2776 | |
2777 /* | |
2778 * Get name of file 'n' in the buffer list. | |
2779 * When the file has no name an empty string is returned. | |
2780 * home_replace() is used to shorten the file name (used for marks). | |
2781 * Returns a pointer to allocated memory, of NULL when failed. | |
2782 */ | |
2783 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2784 buflist_nr2name( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2785 int n, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2786 int fullname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2787 int helptail) /* for help buffers return tail only */ |
7 | 2788 { |
2789 buf_T *buf; | |
2790 | |
2791 buf = buflist_findnr(n); | |
2792 if (buf == NULL) | |
2793 return NULL; | |
2794 return home_replace_save(helptail ? buf : NULL, | |
2795 fullname ? buf->b_ffname : buf->b_fname); | |
2796 } | |
2797 | |
2798 /* | |
2799 * Set the "lnum" and "col" for the buffer "buf" and the current window. | |
2800 * When "copy_options" is TRUE save the local window option values. | |
2801 * When "lnum" is 0 only do the options. | |
2802 */ | |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17225
diff
changeset
|
2803 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2804 buflist_setfpos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2805 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2806 win_T *win, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2807 linenr_T lnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2808 colnr_T col, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2809 int copy_options) |
7 | 2810 { |
2811 wininfo_T *wip; | |
2812 | |
2813 for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) | |
2814 if (wip->wi_win == win) | |
2815 break; | |
2816 if (wip == NULL) | |
2817 { | |
2818 /* 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
|
2819 wip = ALLOC_CLEAR_ONE(wininfo_T); |
7 | 2820 if (wip == NULL) |
2821 return; | |
2822 wip->wi_win = win; | |
2823 if (lnum == 0) /* set lnum even when it's 0 */ | |
2824 lnum = 1; | |
2825 } | |
2826 else | |
2827 { | |
2828 /* remove the entry from the list */ | |
2829 if (wip->wi_prev) | |
2830 wip->wi_prev->wi_next = wip->wi_next; | |
2831 else | |
2832 buf->b_wininfo = wip->wi_next; | |
2833 if (wip->wi_next) | |
2834 wip->wi_next->wi_prev = wip->wi_prev; | |
2835 if (copy_options && wip->wi_optset) | |
2836 { | |
2837 clear_winopt(&wip->wi_opt); | |
2838 #ifdef FEAT_FOLDING | |
2839 deleteFoldRecurse(&wip->wi_folds); | |
2840 #endif | |
2841 } | |
2842 } | |
2843 if (lnum != 0) | |
2844 { | |
2845 wip->wi_fpos.lnum = lnum; | |
2846 wip->wi_fpos.col = col; | |
2847 } | |
2848 if (copy_options) | |
2849 { | |
2850 /* Save the window-specific option values. */ | |
2851 copy_winopt(&win->w_onebuf_opt, &wip->wi_opt); | |
2852 #ifdef FEAT_FOLDING | |
2853 wip->wi_fold_manual = win->w_fold_manual; | |
2854 cloneFoldGrowArray(&win->w_folds, &wip->wi_folds); | |
2855 #endif | |
2856 wip->wi_optset = TRUE; | |
2857 } | |
2858 | |
2859 /* insert the entry in front of the list */ | |
2860 wip->wi_next = buf->b_wininfo; | |
2861 buf->b_wininfo = wip; | |
2862 wip->wi_prev = NULL; | |
2863 if (wip->wi_next) | |
2864 wip->wi_next->wi_prev = wip; | |
2865 | |
2866 return; | |
2867 } | |
2868 | |
1743 | 2869 #ifdef FEAT_DIFF |
2870 /* | |
2871 * Return TRUE when "wip" has 'diff' set and the diff is only for another tab | |
2872 * page. That's because a diff is local to a tab page. | |
2873 */ | |
2874 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2875 wininfo_other_tab_diff(wininfo_T *wip) |
1743 | 2876 { |
2877 win_T *wp; | |
2878 | |
2879 if (wip->wi_opt.wo_diff) | |
2880 { | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
2881 FOR_ALL_WINDOWS(wp) |
1743 | 2882 /* return FALSE when it's a window in the current tab page, thus |
2883 * the buffer was in diff mode here */ | |
2884 if (wip->wi_win == wp) | |
2885 return FALSE; | |
2886 return TRUE; | |
2887 } | |
2888 return FALSE; | |
2889 } | |
2890 #endif | |
2891 | |
7 | 2892 /* |
2893 * Find info for the current window in buffer "buf". | |
2894 * If not found, return the info for the most recently used window. | |
1743 | 2895 * When "skip_diff_buffer" is TRUE avoid windows with 'diff' set that is in |
2896 * another tab page. | |
7 | 2897 * Returns NULL when there isn't any info. |
2898 */ | |
2899 static wininfo_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2900 find_wininfo( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2901 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2902 int skip_diff_buffer UNUSED) |
7 | 2903 { |
2904 wininfo_T *wip; | |
2905 | |
2906 for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) | |
1743 | 2907 if (wip->wi_win == curwin |
2908 #ifdef FEAT_DIFF | |
2909 && (!skip_diff_buffer || !wininfo_other_tab_diff(wip)) | |
2910 #endif | |
2911 ) | |
7 | 2912 break; |
1743 | 2913 |
2914 /* If no wininfo for curwin, use the first in the list (that doesn't have | |
2915 * 'diff' set and is in another tab page). */ | |
2916 if (wip == NULL) | |
2917 { | |
2918 #ifdef FEAT_DIFF | |
2919 if (skip_diff_buffer) | |
2920 { | |
2921 for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) | |
2922 if (!wininfo_other_tab_diff(wip)) | |
2923 break; | |
2924 } | |
2925 else | |
2926 #endif | |
2927 wip = buf->b_wininfo; | |
2928 } | |
7 | 2929 return wip; |
2930 } | |
2931 | |
2932 /* | |
2933 * Reset the local window options to the values last used in this window. | |
2934 * If the buffer wasn't used in this window before, use the values from | |
2935 * the most recently used window. If the values were never set, use the | |
2936 * global values for the window. | |
2937 */ | |
2938 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2939 get_winopts(buf_T *buf) |
7 | 2940 { |
2941 wininfo_T *wip; | |
2942 | |
2943 clear_winopt(&curwin->w_onebuf_opt); | |
2944 #ifdef FEAT_FOLDING | |
2945 clearFolding(curwin); | |
2946 #endif | |
2947 | |
1743 | 2948 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
|
2949 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
|
2950 && wip->wi_win != curwin && wip->wi_win->w_buffer == buf) |
7 | 2951 { |
13931
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
2952 /* The buffer is currently displayed in the window: use the actual |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
2953 * option values instead of the saved (possibly outdated) values. */ |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
2954 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
|
2955 |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
2956 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
|
2957 #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
|
2958 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
|
2959 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
|
2960 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
|
2961 #endif |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
2962 } |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
2963 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
|
2964 { |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
2965 /* the buffer was displayed in the current window earlier */ |
7 | 2966 copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt); |
2967 #ifdef FEAT_FOLDING | |
2968 curwin->w_fold_manual = wip->wi_fold_manual; | |
2969 curwin->w_foldinvalid = TRUE; | |
2970 cloneFoldGrowArray(&wip->wi_folds, &curwin->w_folds); | |
2971 #endif | |
2972 } | |
2973 else | |
2974 copy_winopt(&curwin->w_allbuf_opt, &curwin->w_onebuf_opt); | |
2975 | |
2976 #ifdef FEAT_FOLDING | |
2977 /* Set 'foldlevel' to 'foldlevelstart' if it's not negative. */ | |
2978 if (p_fdls >= 0) | |
2979 curwin->w_p_fdl = p_fdls; | |
2980 #endif | |
18156
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
2981 after_copy_winopt(curwin); |
7 | 2982 } |
2983 | |
2984 /* | |
2985 * Find the position (lnum and col) for the buffer 'buf' for the current | |
2986 * window. | |
2987 * Returns a pointer to no_position if no position is found. | |
2988 */ | |
2989 pos_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2990 buflist_findfpos(buf_T *buf) |
7 | 2991 { |
2992 wininfo_T *wip; | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15595
diff
changeset
|
2993 static pos_T no_position = {1, 0, 0}; |
7 | 2994 |
1743 | 2995 wip = find_wininfo(buf, FALSE); |
7 | 2996 if (wip != NULL) |
2997 return &(wip->wi_fpos); | |
2998 else | |
2999 return &no_position; | |
3000 } | |
3001 | |
3002 /* | |
3003 * Find the lnum for the buffer 'buf' for the current window. | |
3004 */ | |
3005 linenr_T | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3006 buflist_findlnum(buf_T *buf) |
7 | 3007 { |
3008 return buflist_findfpos(buf)->lnum; | |
3009 } | |
3010 | |
3011 /* | |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3012 * List all known file names (for :files and :buffers command). |
7 | 3013 */ |
3014 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3015 buflist_list(exarg_T *eap) |
7 | 3016 { |
3017 buf_T *buf; | |
3018 int len; | |
3019 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
|
3020 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
|
3021 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
|
3022 #ifdef FEAT_TERMINAL |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3023 int job_running; |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3024 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
|
3025 #endif |
7 | 3026 |
3027 for (buf = firstbuf; buf != NULL && !got_int; buf = buf->b_next) | |
3028 { | |
13555
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3029 #ifdef FEAT_TERMINAL |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3030 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
|
3031 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
|
3032 #endif |
7 | 3033 /* skip unlisted buffers, unless ! was used */ |
6945 | 3034 if ((!buf->b_p_bl && !eap->forceit && !vim_strchr(eap->arg, 'u')) |
3035 || (vim_strchr(eap->arg, 'u') && buf->b_p_bl) | |
3036 || (vim_strchr(eap->arg, '+') | |
3037 && ((buf->b_flags & BF_READERR) || !bufIsChanged(buf))) | |
3038 || (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
|
3039 && (buf->b_ml.ml_mfp == NULL || buf->b_nwindows == 0)) |
6945 | 3040 || (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
|
3041 && (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
|
3042 #ifdef FEAT_TERMINAL |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3043 || (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
|
3044 && (!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
|
3045 || (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
|
3046 && (!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
|
3047 || (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
|
3048 && (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
|
3049 #endif |
6945 | 3050 || (vim_strchr(eap->arg, '-') && buf->b_p_ma) |
3051 || (vim_strchr(eap->arg, '=') && !buf->b_p_ro) | |
3052 || (vim_strchr(eap->arg, 'x') && !(buf->b_flags & BF_READERR)) | |
3053 || (vim_strchr(eap->arg, '%') && buf != curbuf) | |
3054 || (vim_strchr(eap->arg, '#') | |
3055 && (buf == curbuf || curwin->w_alt_fnum != buf->b_fnum))) | |
7 | 3056 continue; |
3057 if (buf_spname(buf) != NULL) | |
3839 | 3058 vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1); |
7 | 3059 else |
3060 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
|
3061 if (message_filtered(NameBuff)) |
af161c1f530a
commit https://github.com/vim/vim/commit/77401add71853d7a3da7ccc489f2a1bca58551ec
Christian Brabandt <cb@256bit.org>
parents:
9911
diff
changeset
|
3062 continue; |
af161c1f530a
commit https://github.com/vim/vim/commit/77401add71853d7a3da7ccc489f2a1bca58551ec
Christian Brabandt <cb@256bit.org>
parents:
9911
diff
changeset
|
3063 |
12110
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3064 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
|
3065 : (bufIsChanged(buf) ? '+' : ' '); |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3066 #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
|
3067 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
|
3068 { |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
3069 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
|
3070 ro_char = '?'; |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
3071 else |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
3072 ro_char = 'R'; |
12110
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3073 changed_char = ' '; /* bufIsChanged() returns TRUE to avoid |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3074 * closing, but it's not actually changed. */ |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3075 } |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3076 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
|
3077 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
|
3078 else |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3079 #endif |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3080 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
|
3081 |
9943
af161c1f530a
commit https://github.com/vim/vim/commit/77401add71853d7a3da7ccc489f2a1bca58551ec
Christian Brabandt <cb@256bit.org>
parents:
9911
diff
changeset
|
3082 msg_putchar('\n'); |
302 | 3083 len = vim_snprintf((char *)IObuff, IOSIZE - 20, "%3d%c%c%c%c%c \"%s\"", |
7 | 3084 buf->b_fnum, |
3085 buf->b_p_bl ? ' ' : 'u', | |
3086 buf == curbuf ? '%' : | |
3087 (curwin->w_alt_fnum == buf->b_fnum ? '#' : ' '), | |
3088 buf->b_ml.ml_mfp == NULL ? ' ' : | |
3089 (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
|
3090 ro_char, |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3091 changed_char, |
300 | 3092 NameBuff); |
7572
992fe73d4ee6
commit https://github.com/vim/vim/commit/507edf63df75fe228e0f76b845b58d60266e65d8
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
3093 if (len > IOSIZE - 20) |
992fe73d4ee6
commit https://github.com/vim/vim/commit/507edf63df75fe228e0f76b845b58d60266e65d8
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
3094 len = IOSIZE - 20; |
7 | 3095 |
3096 /* put "line 999" in column 40 or after the file name */ | |
3097 i = 40 - vim_strsize(IObuff); | |
3098 do | |
3099 IObuff[len++] = ' '; | |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
16082
diff
changeset
|
3100 while (--i > 0 && len < IOSIZE - 18); |
1869 | 3101 vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), |
3102 _("line %ld"), buf == curbuf ? curwin->w_cursor.lnum | |
272 | 3103 : (long)buflist_findlnum(buf)); |
7 | 3104 msg_outtrans(IObuff); |
3105 out_flush(); /* output one line at a time */ | |
3106 ui_breakcheck(); | |
3107 } | |
3108 } | |
3109 | |
3110 /* | |
3111 * Get file name and line number for file 'fnum'. | |
3112 * Used by DoOneCmd() for translating '%' and '#'. | |
3113 * Used by insert_reg() and cmdline_paste() for '#' register. | |
3114 * Return FAIL if not found, OK for success. | |
3115 */ | |
3116 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3117 buflist_name_nr( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3118 int fnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3119 char_u **fname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3120 linenr_T *lnum) |
7 | 3121 { |
3122 buf_T *buf; | |
3123 | |
3124 buf = buflist_findnr(fnum); | |
3125 if (buf == NULL || buf->b_fname == NULL) | |
3126 return FAIL; | |
3127 | |
3128 *fname = buf->b_fname; | |
3129 *lnum = buflist_findlnum(buf); | |
3130 | |
3131 return OK; | |
3132 } | |
3133 | |
3134 /* | |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3135 * 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
|
3136 * "sfname_arg". |
7 | 3137 * The file name with the full path is also remembered, for when :cd is used. |
3138 * Returns FAIL for failure (file name already in use by other buffer) | |
3139 * OK otherwise. | |
3140 */ | |
3141 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3142 setfname( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3143 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
|
3144 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
|
3145 char_u *sfname_arg, |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3146 int message) /* give message when buffer already exists */ |
7 | 3147 { |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3148 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
|
3149 char_u *sfname = sfname_arg; |
42 | 3150 buf_T *obuf = NULL; |
7 | 3151 #ifdef UNIX |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3152 stat_T st; |
7 | 3153 #endif |
3154 | |
3155 if (ffname == NULL || *ffname == NUL) | |
3156 { | |
3157 /* 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
|
3158 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
|
3159 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
|
3160 else |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3161 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
|
3162 VIM_CLEAR(buf->b_ffname); |
7 | 3163 #ifdef UNIX |
3164 st.st_dev = (dev_T)-1; | |
3165 #endif | |
3166 } | |
3167 else | |
3168 { | |
3169 fname_expand(buf, &ffname, &sfname); /* will allocate ffname */ | |
3170 if (ffname == NULL) /* out of memory */ | |
3171 return FAIL; | |
3172 | |
3173 /* | |
3174 * if the file name is already used in another buffer: | |
3175 * - if the buffer is loaded, fail | |
3176 * - if the buffer is not loaded, delete it from the list | |
3177 */ | |
3178 #ifdef UNIX | |
3179 if (mch_stat((char *)ffname, &st) < 0) | |
3180 st.st_dev = (dev_T)-1; | |
42 | 3181 #endif |
3182 if (!(buf->b_flags & BF_DUMMY)) | |
3183 #ifdef UNIX | |
3184 obuf = buflist_findname_stat(ffname, &st); | |
7 | 3185 #else |
42 | 3186 obuf = buflist_findname(ffname); |
7 | 3187 #endif |
3188 if (obuf != NULL && obuf != buf) | |
3189 { | |
3190 if (obuf->b_ml.ml_mfp != NULL) /* it's loaded, fail */ | |
3191 { | |
3192 if (message) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
3193 emsg(_("E95: Buffer with this name already exists")); |
7 | 3194 vim_free(ffname); |
3195 return FAIL; | |
3196 } | |
3365 | 3197 /* delete from the list */ |
3198 close_buffer(NULL, obuf, DOBUF_WIPE, FALSE); | |
7 | 3199 } |
3200 sfname = vim_strsave(sfname); | |
3201 if (ffname == NULL || sfname == NULL) | |
3202 { | |
3203 vim_free(sfname); | |
3204 vim_free(ffname); | |
3205 return FAIL; | |
3206 } | |
3207 #ifdef USE_FNAME_CASE | |
15794
0d8291665b59
patch 8.1.0904: USE_LONG_FNAME never defined
Bram Moolenaar <Bram@vim.org>
parents:
15774
diff
changeset
|
3208 fname_case(sfname, 0); /* set correct case for short file name */ |
7 | 3209 #endif |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3210 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
|
3211 vim_free(buf->b_sfname); |
7 | 3212 vim_free(buf->b_ffname); |
3213 buf->b_ffname = ffname; | |
3214 buf->b_sfname = sfname; | |
3215 } | |
3216 buf->b_fname = buf->b_sfname; | |
3217 #ifdef UNIX | |
3218 if (st.st_dev == (dev_T)-1) | |
1873 | 3219 buf->b_dev_valid = FALSE; |
7 | 3220 else |
3221 { | |
1873 | 3222 buf->b_dev_valid = TRUE; |
7 | 3223 buf->b_dev = st.st_dev; |
3224 buf->b_ino = st.st_ino; | |
3225 } | |
3226 #endif | |
3227 | |
3228 buf->b_shortname = FALSE; | |
3229 | |
3230 buf_name_changed(buf); | |
3231 return OK; | |
3232 } | |
3233 | |
3234 /* | |
41 | 3235 * Crude way of changing the name of a buffer. Use with care! |
3236 * The name should be relative to the current directory. | |
3237 */ | |
3238 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3239 buf_set_name(int fnum, char_u *name) |
41 | 3240 { |
3241 buf_T *buf; | |
3242 | |
3243 buf = buflist_findnr(fnum); | |
3244 if (buf != NULL) | |
3245 { | |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3246 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
|
3247 vim_free(buf->b_sfname); |
41 | 3248 vim_free(buf->b_ffname); |
844 | 3249 buf->b_ffname = vim_strsave(name); |
3250 buf->b_sfname = NULL; | |
3251 /* Allocate ffname and expand into full path. Also resolves .lnk | |
3252 * files on Win32. */ | |
3253 fname_expand(buf, &buf->b_ffname, &buf->b_sfname); | |
41 | 3254 buf->b_fname = buf->b_sfname; |
3255 } | |
3256 } | |
3257 | |
3258 /* | |
7 | 3259 * Take care of what needs to be done when the name of buffer "buf" has |
3260 * changed. | |
3261 */ | |
3262 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3263 buf_name_changed(buf_T *buf) |
7 | 3264 { |
3265 /* | |
3266 * If the file name changed, also change the name of the swapfile | |
3267 */ | |
3268 if (buf->b_ml.ml_mfp != NULL) | |
3269 ml_setname(buf); | |
3270 | |
3271 if (curwin->w_buffer == buf) | |
3272 check_arg_idx(curwin); /* check file name for arg list */ | |
3273 #ifdef FEAT_TITLE | |
3274 maketitle(); /* set window title */ | |
3275 #endif | |
3276 status_redraw_all(); /* status lines need to be redrawn */ | |
3277 fmarks_check_names(buf); /* check named file marks */ | |
3278 ml_timestamp(buf); /* reset timestamp */ | |
3279 } | |
3280 | |
3281 /* | |
3282 * set alternate file name for current window | |
3283 * | |
3284 * Used by do_one_cmd(), do_write() and do_ecmd(). | |
3285 * Return the buffer. | |
3286 */ | |
3287 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3288 setaltfname( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3289 char_u *ffname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3290 char_u *sfname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3291 linenr_T lnum) |
7 | 3292 { |
3293 buf_T *buf; | |
3294 | |
3295 /* Create a buffer. 'buflisted' is not set if it's a new buffer */ | |
3296 buf = buflist_new(ffname, sfname, lnum, 0); | |
22 | 3297 if (buf != NULL && !cmdmod.keepalt) |
7 | 3298 curwin->w_alt_fnum = buf->b_fnum; |
3299 return buf; | |
3300 } | |
3301 | |
3302 /* | |
3303 * Get alternate file name for current window. | |
3304 * Return NULL if there isn't any, and give error message if requested. | |
3305 */ | |
3306 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3307 getaltfname( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3308 int errmsg) /* give error message */ |
7 | 3309 { |
3310 char_u *fname; | |
3311 linenr_T dummy; | |
3312 | |
3313 if (buflist_name_nr(0, &fname, &dummy) == FAIL) | |
3314 { | |
3315 if (errmsg) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
3316 emsg(_(e_noalt)); |
7 | 3317 return NULL; |
3318 } | |
3319 return fname; | |
3320 } | |
3321 | |
3322 /* | |
3323 * Add a file name to the buflist and return its number. | |
3324 * Uses same flags as buflist_new(), except BLN_DUMMY. | |
3325 * | |
3326 * used by qf_init(), main() and doarglist() | |
3327 */ | |
3328 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3329 buflist_add(char_u *fname, int flags) |
7 | 3330 { |
3331 buf_T *buf; | |
3332 | |
3333 buf = buflist_new(fname, NULL, (linenr_T)0, flags); | |
3334 if (buf != NULL) | |
3335 return buf->b_fnum; | |
3336 return 0; | |
3337 } | |
3338 | |
3339 #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) | |
3340 /* | |
3341 * Adjust slashes in file names. Called after 'shellslash' was set. | |
3342 */ | |
3343 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3344 buflist_slash_adjust(void) |
7 | 3345 { |
3346 buf_T *bp; | |
3347 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
3348 FOR_ALL_BUFFERS(bp) |
7 | 3349 { |
3350 if (bp->b_ffname != NULL) | |
3351 slash_adjust(bp->b_ffname); | |
3352 if (bp->b_sfname != NULL) | |
3353 slash_adjust(bp->b_sfname); | |
3354 } | |
3355 } | |
3356 #endif | |
3357 | |
3358 /* | |
1743 | 3359 * Set alternate cursor position for the current buffer and window "win". |
7 | 3360 * Also save the local window option values. |
3361 */ | |
3362 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3363 buflist_altfpos(win_T *win) |
7 | 3364 { |
1743 | 3365 buflist_setfpos(curbuf, win, win->w_cursor.lnum, win->w_cursor.col, TRUE); |
7 | 3366 } |
3367 | |
3368 /* | |
3369 * Return TRUE if 'ffname' is not the same file as current file. | |
3370 * Fname must have a full path (expanded by mch_FullName()). | |
3371 */ | |
3372 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3373 otherfile(char_u *ffname) |
7 | 3374 { |
3375 return otherfile_buf(curbuf, ffname | |
3376 #ifdef UNIX | |
3377 , NULL | |
3378 #endif | |
3379 ); | |
3380 } | |
3381 | |
3382 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3383 otherfile_buf( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3384 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3385 char_u *ffname |
7 | 3386 #ifdef UNIX |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3387 , stat_T *stp |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3388 #endif |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3389 ) |
7 | 3390 { |
3391 /* no name is different */ | |
3392 if (ffname == NULL || *ffname == NUL || buf->b_ffname == NULL) | |
3393 return TRUE; | |
3394 if (fnamecmp(ffname, buf->b_ffname) == 0) | |
3395 return FALSE; | |
3396 #ifdef UNIX | |
3397 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3398 stat_T st; |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3399 |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3400 /* If no stat_T given, get it now */ |
7 | 3401 if (stp == NULL) |
3402 { | |
1873 | 3403 if (!buf->b_dev_valid || mch_stat((char *)ffname, &st) < 0) |
7 | 3404 st.st_dev = (dev_T)-1; |
3405 stp = &st; | |
3406 } | |
3407 /* Use dev/ino to check if the files are the same, even when the names | |
3408 * are different (possible with links). Still need to compare the | |
3409 * name above, for when the file doesn't exist yet. | |
3410 * Problem: The dev/ino changes when a file is deleted (and created | |
3411 * again) and remains the same when renamed/moved. We don't want to | |
3412 * mch_stat() each buffer each time, that would be too slow. Get the | |
3413 * dev/ino again when they appear to match, but not when they appear | |
3414 * to be different: Could skip a buffer when it's actually the same | |
3415 * file. */ | |
3416 if (buf_same_ino(buf, stp)) | |
3417 { | |
3418 buf_setino(buf); | |
3419 if (buf_same_ino(buf, stp)) | |
3420 return FALSE; | |
3421 } | |
3422 } | |
3423 #endif | |
3424 return TRUE; | |
3425 } | |
3426 | |
3427 #if defined(UNIX) || defined(PROTO) | |
3428 /* | |
3429 * Set inode and device number for a buffer. | |
3430 * Must always be called when b_fname is changed!. | |
3431 */ | |
3432 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3433 buf_setino(buf_T *buf) |
7 | 3434 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3435 stat_T st; |
7 | 3436 |
3437 if (buf->b_fname != NULL && mch_stat((char *)buf->b_fname, &st) >= 0) | |
3438 { | |
1873 | 3439 buf->b_dev_valid = TRUE; |
7 | 3440 buf->b_dev = st.st_dev; |
3441 buf->b_ino = st.st_ino; | |
3442 } | |
3443 else | |
1873 | 3444 buf->b_dev_valid = FALSE; |
7 | 3445 } |
3446 | |
3447 /* | |
3448 * Return TRUE if dev/ino in buffer "buf" matches with "stp". | |
3449 */ | |
3450 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3451 buf_same_ino( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3452 buf_T *buf, |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3453 stat_T *stp) |
7 | 3454 { |
1873 | 3455 return (buf->b_dev_valid |
7 | 3456 && stp->st_dev == buf->b_dev |
3457 && stp->st_ino == buf->b_ino); | |
3458 } | |
3459 #endif | |
3460 | |
667 | 3461 /* |
3462 * Print info about the current buffer. | |
3463 */ | |
7 | 3464 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3465 fileinfo( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3466 int fullname, /* when non-zero print full path */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3467 int shorthelp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3468 int dont_truncate) |
7 | 3469 { |
3470 char_u *name; | |
3471 int n; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3472 char *p; |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3473 char *buffer; |
272 | 3474 size_t len; |
7 | 3475 |
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
|
3476 buffer = alloc(IOSIZE); |
7 | 3477 if (buffer == NULL) |
3478 return; | |
3479 | |
3480 if (fullname > 1) /* 2 CTRL-G: include buffer number */ | |
3481 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3482 vim_snprintf(buffer, IOSIZE, "buf %d: ", curbuf->b_fnum); |
7 | 3483 p = buffer + STRLEN(buffer); |
3484 } | |
3485 else | |
3486 p = buffer; | |
3487 | |
3488 *p++ = '"'; | |
3489 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
|
3490 vim_strncpy((char_u *)p, buf_spname(curbuf), IOSIZE - (p - buffer) - 1); |
7 | 3491 else |
3492 { | |
3493 if (!fullname && curbuf->b_fname != NULL) | |
3494 name = curbuf->b_fname; | |
3495 else | |
3496 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
|
3497 home_replace(shorthelp ? curbuf : NULL, name, (char_u *)p, |
7 | 3498 (int)(IOSIZE - (p - buffer)), TRUE); |
3499 } | |
3500 | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3501 vim_snprintf_add(buffer, IOSIZE, "\"%s%s%s%s%s%s", |
7 | 3502 curbufIsChanged() ? (shortmess(SHM_MOD) |
3503 ? " [+]" : _(" [Modified]")) : " ", | |
3504 (curbuf->b_flags & BF_NOTEDITED) | |
3505 #ifdef FEAT_QUICKFIX | |
3506 && !bt_dontwrite(curbuf) | |
3507 #endif | |
3508 ? _("[Not edited]") : "", | |
3509 (curbuf->b_flags & BF_NEW) | |
3510 #ifdef FEAT_QUICKFIX | |
3511 && !bt_dontwrite(curbuf) | |
3512 #endif | |
3513 ? _("[New file]") : "", | |
3514 (curbuf->b_flags & BF_READERR) ? _("[Read errors]") : "", | |
4795
8360a59aa04b
updated for version 7.3.1144
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
3515 curbuf->b_p_ro ? (shortmess(SHM_RO) ? _("[RO]") |
7 | 3516 : _("[readonly]")) : "", |
3517 (curbufIsChanged() || (curbuf->b_flags & BF_WRITE_MASK) | |
3518 || curbuf->b_p_ro) ? | |
3519 " " : ""); | |
3520 /* With 32 bit longs and more than 21,474,836 lines multiplying by 100 | |
3521 * causes an overflow, thus for large numbers divide instead. */ | |
3522 if (curwin->w_cursor.lnum > 1000000L) | |
3523 n = (int)(((long)curwin->w_cursor.lnum) / | |
3524 ((long)curbuf->b_ml.ml_line_count / 100L)); | |
3525 else | |
3526 n = (int)(((long)curwin->w_cursor.lnum * 100L) / | |
3527 (long)curbuf->b_ml.ml_line_count); | |
3528 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
|
3529 vim_snprintf_add(buffer, IOSIZE, "%s", _(no_lines_msg)); |
7 | 3530 #ifdef FEAT_CMDL_INFO |
3531 else if (p_ru) | |
3532 /* 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
|
3533 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
|
3534 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
|
3535 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
|
3536 (long)curbuf->b_ml.ml_line_count, n); |
7 | 3537 #endif |
3538 else | |
3539 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3540 vim_snprintf_add(buffer, IOSIZE, |
7 | 3541 _("line %ld of %ld --%d%%-- col "), |
3542 (long)curwin->w_cursor.lnum, | |
3543 (long)curbuf->b_ml.ml_line_count, | |
3544 n); | |
3545 validate_virtcol(); | |
1869 | 3546 len = STRLEN(buffer); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3547 col_print((char_u *)buffer + len, IOSIZE - len, |
7 | 3548 (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1); |
3549 } | |
3550 | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3551 (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
|
3552 !shortmess(SHM_FILE)); |
7 | 3553 |
3554 if (dont_truncate) | |
3555 { | |
3556 /* Temporarily set msg_scroll to avoid the message being truncated. | |
3557 * First call msg_start() to get the message in the right place. */ | |
3558 msg_start(); | |
3559 n = msg_scroll; | |
3560 msg_scroll = TRUE; | |
3561 msg(buffer); | |
3562 msg_scroll = n; | |
3563 } | |
3564 else | |
3565 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3566 p = (char *)msg_trunc_attr(buffer, FALSE, 0); |
7 | 3567 if (restart_edit != 0 || (msg_scrolled && !need_wait_return)) |
3568 /* Need to repeat the message after redrawing when: | |
3569 * - When restart_edit is set (otherwise there will be a delay | |
3570 * before redrawing). | |
3571 * - When the screen was scrolled but there is no wait-return | |
3572 * prompt. */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3573 set_keep_msg((char_u *)p, 0); |
7 | 3574 } |
3575 | |
3576 vim_free(buffer); | |
3577 } | |
3578 | |
3579 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3580 col_print( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3581 char_u *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3582 size_t buflen, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3583 int col, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3584 int vcol) |
7 | 3585 { |
3586 if (col == vcol) | |
1869 | 3587 vim_snprintf((char *)buf, buflen, "%d", col); |
7 | 3588 else |
1869 | 3589 vim_snprintf((char *)buf, buflen, "%d-%d", col, vcol); |
7 | 3590 } |
3591 | |
3592 #if defined(FEAT_TITLE) || defined(PROTO) | |
3593 static char_u *lasttitle = NULL; | |
3594 static char_u *lasticon = NULL; | |
3595 | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3596 /* |
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3597 * 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
|
3598 */ |
7 | 3599 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3600 maketitle(void) |
7 | 3601 { |
3602 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
|
3603 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
|
3604 char_u *icon_str = NULL; |
7 | 3605 int maxlen = 0; |
3606 int len; | |
3607 int mustset; | |
3608 char_u buf[IOSIZE]; | |
3609 int off; | |
3610 | |
3611 if (!redrawing()) | |
3612 { | |
3613 /* Postpone updating the title when 'lazyredraw' is set. */ | |
3614 need_maketitle = TRUE; | |
3615 return; | |
3616 } | |
3617 | |
3618 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
|
3619 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
|
3620 return; // nothing to do |
7 | 3621 |
3622 if (p_title) | |
3623 { | |
3624 if (p_titlelen > 0) | |
3625 { | |
3626 maxlen = p_titlelen * Columns / 100; | |
3627 if (maxlen < 10) | |
3628 maxlen = 10; | |
3629 } | |
3630 | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3631 title_str = buf; |
7 | 3632 if (*p_titlestring != NUL) |
3633 { | |
3634 #ifdef FEAT_STL_OPT | |
771 | 3635 if (stl_syntax & STL_IN_TITLE) |
3636 { | |
3637 int use_sandbox = FALSE; | |
3638 int save_called_emsg = called_emsg; | |
675 | 3639 |
3640 # ifdef FEAT_EVAL | |
771 | 3641 use_sandbox = was_set_insecurely((char_u *)"titlestring", 0); |
675 | 3642 # endif |
771 | 3643 called_emsg = FALSE; |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3644 build_stl_str_hl(curwin, title_str, sizeof(buf), |
675 | 3645 p_titlestring, use_sandbox, |
681 | 3646 0, maxlen, NULL, NULL); |
771 | 3647 if (called_emsg) |
3648 set_string_option_direct((char_u *)"titlestring", -1, | |
3649 (char_u *)"", OPT_FREE, SID_ERROR); | |
3650 called_emsg |= save_called_emsg; | |
3651 } | |
7 | 3652 else |
3653 #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
|
3654 title_str = p_titlestring; |
7 | 3655 } |
3656 else | |
3657 { | |
3658 /* format: "fname + (path) (1 of 2) - VIM" */ | |
3659 | |
3780 | 3660 #define SPACE_FOR_FNAME (IOSIZE - 100) |
3661 #define SPACE_FOR_DIR (IOSIZE - 20) | |
3662 #define SPACE_FOR_ARGNR (IOSIZE - 10) /* at least room for " - VIM" */ | |
7 | 3663 if (curbuf->b_fname == NULL) |
3780 | 3664 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
|
3665 #ifdef FEAT_TERMINAL |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3666 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
|
3667 { |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3668 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
|
3669 SPACE_FOR_FNAME); |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3670 } |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3671 #endif |
7 | 3672 else |
3673 { | |
3674 p = transstr(gettail(curbuf->b_fname)); | |
3780 | 3675 vim_strncpy(buf, p, SPACE_FOR_FNAME); |
7 | 3676 vim_free(p); |
3677 } | |
3678 | |
11772
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3679 #ifdef FEAT_TERMINAL |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3680 if (curbuf->b_term == NULL) |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3681 #endif |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3682 switch (bufIsChanged(curbuf) |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3683 + (curbuf->b_p_ro * 2) |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3684 + (!curbuf->b_p_ma * 4)) |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3685 { |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3686 case 1: STRCAT(buf, " +"); break; |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3687 case 2: STRCAT(buf, " ="); break; |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3688 case 3: STRCAT(buf, " =+"); break; |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3689 case 4: |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3690 case 6: STRCAT(buf, " -"); break; |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3691 case 5: |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3692 case 7: STRCAT(buf, " -+"); break; |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3693 } |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3694 |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3695 if (curbuf->b_fname != NULL |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3696 #ifdef FEAT_TERMINAL |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3697 && curbuf->b_term == NULL |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3698 #endif |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3699 ) |
7 | 3700 { |
3701 /* Get path of file, replace home dir with ~ */ | |
3702 off = (int)STRLEN(buf); | |
3703 buf[off++] = ' '; | |
3704 buf[off++] = '('; | |
3705 home_replace(curbuf, curbuf->b_ffname, | |
3780 | 3706 buf + off, SPACE_FOR_DIR - off, TRUE); |
7 | 3707 #ifdef BACKSLASH_IN_FILENAME |
3708 /* avoid "c:/name" to be reduced to "c" */ | |
3709 if (isalpha(buf[off]) && buf[off + 1] == ':') | |
3710 off += 2; | |
3711 #endif | |
3712 /* remove the file name */ | |
39 | 3713 p = gettail_sep(buf + off); |
7 | 3714 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
|
3715 { |
11772
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3716 /* must be a help buffer */ |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3717 vim_strncpy(buf + off, (char_u *)_("help"), |
3780 | 3718 (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
|
3719 } |
7 | 3720 else |
3721 *p = NUL; | |
39 | 3722 |
3780 | 3723 /* Translate unprintable chars and concatenate. Keep some |
3724 * room for the server name. When there is no room (very long | |
3725 * file name) use (...). */ | |
3726 if (off < SPACE_FOR_DIR) | |
3727 { | |
3728 p = transstr(buf + off); | |
3729 vim_strncpy(buf + off, p, (size_t)(SPACE_FOR_DIR - off)); | |
3730 vim_free(p); | |
3731 } | |
3732 else | |
3733 { | |
3734 vim_strncpy(buf + off, (char_u *)"...", | |
3735 (size_t)(SPACE_FOR_ARGNR - off)); | |
3736 } | |
7 | 3737 STRCAT(buf, ")"); |
3738 } | |
3739 | |
3780 | 3740 append_arg_number(curwin, buf, SPACE_FOR_ARGNR, FALSE); |
7 | 3741 |
3742 #if defined(FEAT_CLIENTSERVER) | |
3743 if (serverName != NULL) | |
3744 { | |
3745 STRCAT(buf, " - "); | |
2768 | 3746 vim_strcat(buf, serverName, IOSIZE); |
7 | 3747 } |
3748 else | |
3749 #endif | |
3750 STRCAT(buf, " - VIM"); | |
3751 | |
3752 if (maxlen > 0) | |
3753 { | |
3754 /* make it shorter by removing a bit in the middle */ | |
3277 | 3755 if (vim_strsize(buf) > maxlen) |
3756 trunc_string(buf, buf, maxlen, IOSIZE); | |
7 | 3757 } |
3758 } | |
3759 } | |
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 mustset = value_changed(title_str, &lasttitle); |
7 | 3761 |
3762 if (p_icon) | |
3763 { | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3764 icon_str = buf; |
7 | 3765 if (*p_iconstring != NUL) |
3766 { | |
3767 #ifdef FEAT_STL_OPT | |
771 | 3768 if (stl_syntax & STL_IN_ICON) |
3769 { | |
3770 int use_sandbox = FALSE; | |
3771 int save_called_emsg = called_emsg; | |
675 | 3772 |
3773 # ifdef FEAT_EVAL | |
771 | 3774 use_sandbox = was_set_insecurely((char_u *)"iconstring", 0); |
675 | 3775 # endif |
771 | 3776 called_emsg = FALSE; |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3777 build_stl_str_hl(curwin, icon_str, sizeof(buf), |
675 | 3778 p_iconstring, use_sandbox, |
681 | 3779 0, 0, NULL, NULL); |
771 | 3780 if (called_emsg) |
3781 set_string_option_direct((char_u *)"iconstring", -1, | |
3782 (char_u *)"", OPT_FREE, SID_ERROR); | |
3783 called_emsg |= save_called_emsg; | |
3784 } | |
7 | 3785 else |
3786 #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
|
3787 icon_str = p_iconstring; |
7 | 3788 } |
3789 else | |
3790 { | |
3791 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
|
3792 p = buf_spname(curbuf); |
7 | 3793 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
|
3794 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
|
3795 *icon_str = NUL; |
7 | 3796 /* 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
|
3797 len = (int)STRLEN(p); |
7 | 3798 if (len > 100) |
3799 { | |
3800 len -= 100; | |
3801 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
|
3802 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
|
3803 p += len; |
7 | 3804 } |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3805 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
|
3806 trans_characters(icon_str, IOSIZE); |
7 | 3807 } |
3808 } | |
3809 | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3810 mustset |= value_changed(icon_str, &lasticon); |
7 | 3811 |
3812 if (mustset) | |
3813 resettitle(); | |
3814 } | |
3815 | |
3816 /* | |
3817 * Used for title and icon: Check if "str" differs from "*last". Set "*last" | |
3818 * 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
|
3819 * Return TRUE if resettitle() is to be called. |
7 | 3820 */ |
3821 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
|
3822 value_changed(char_u *str, char_u **last) |
7 | 3823 { |
3824 if ((str == NULL) != (*last == NULL) | |
3825 || (str != NULL && *last != NULL && STRCMP(str, *last) != 0)) | |
3826 { | |
3827 vim_free(*last); | |
3828 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
|
3829 { |
7 | 3830 *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
|
3831 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
|
3832 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
|
3833 } |
7 | 3834 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
|
3835 { |
7 | 3836 *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
|
3837 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
|
3838 } |
7 | 3839 } |
3840 return FALSE; | |
3841 } | |
3842 | |
3843 /* | |
3844 * Put current window title back (used after calling a shell) | |
3845 */ | |
3846 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3847 resettitle(void) |
7 | 3848 { |
3849 mch_settitle(lasttitle, lasticon); | |
3850 } | |
358 | 3851 |
3852 # if defined(EXITFREE) || defined(PROTO) | |
3853 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3854 free_titles(void) |
358 | 3855 { |
3856 vim_free(lasttitle); | |
3857 vim_free(lasticon); | |
3858 } | |
3859 # endif | |
3860 | |
7 | 3861 #endif /* FEAT_TITLE */ |
3862 | |
686 | 3863 #if defined(FEAT_STL_OPT) || defined(FEAT_GUI_TABLINE) || defined(PROTO) |
7 | 3864 /* |
675 | 3865 * Build a string from the status line items in "fmt". |
7 | 3866 * Return length of string in screen cells. |
3867 * | |
675 | 3868 * Normally works for window "wp", except when working for 'tabline' then it |
3869 * is "curwin". | |
3870 * | |
7 | 3871 * Items are drawn interspersed with the text that surrounds it |
3872 * Specials: %-<wid>(xxx%) => group, %= => middle marker, %< => truncation | |
3873 * Item: %-<minwid>.<maxwid><itemch> All but <itemch> are optional | |
3874 * | |
3875 * If maxwidth is not zero, the string will be filled at any middle marker | |
3876 * or truncated if too long, fillchar is used for all whitespace. | |
3877 */ | |
3878 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3879 build_stl_str_hl( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3880 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3881 char_u *out, /* buffer to write into != NameBuff */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3882 size_t outlen, /* length of out[] */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3883 char_u *fmt, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3884 int use_sandbox UNUSED, /* "fmt" was set insecurely, use sandbox */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3885 int fillchar, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3886 int maxwidth, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3887 struct stl_hlrec *hltab, /* return: HL attributes (can be NULL) */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3888 struct stl_hlrec *tabtab) /* return: tab page nrs (can be NULL) */ |
7 | 3889 { |
15557
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3890 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
|
3891 size_t len; |
7 | 3892 char_u *p; |
3893 char_u *s; | |
3894 char_u *t; | |
4333 | 3895 int byteval; |
7 | 3896 #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
|
3897 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
|
3898 buf_T *save_curbuf; |
7 | 3899 #endif |
3900 int empty_line; | |
3901 colnr_T virtcol; | |
3902 long l; | |
3903 long n; | |
3904 int prevchar_isflag; | |
3905 int prevchar_isitem; | |
3906 int itemisflag; | |
3907 int fillable; | |
3908 char_u *str; | |
3909 long num; | |
3910 int width; | |
3911 int itemcnt; | |
3912 int curitem; | |
12660
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
3913 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
|
3914 int group_start_userhl; |
7 | 3915 int groupitem[STL_MAX_ITEM]; |
3916 int groupdepth; | |
3917 struct stl_item | |
3918 { | |
3919 char_u *start; | |
3920 int minwid; | |
3921 int maxwid; | |
3922 enum | |
3923 { | |
3924 Normal, | |
3925 Empty, | |
3926 Group, | |
3927 Middle, | |
3928 Highlight, | |
681 | 3929 TabPage, |
7 | 3930 Trunc |
3931 } type; | |
3932 } item[STL_MAX_ITEM]; | |
3933 int minwid; | |
3934 int maxwid; | |
3935 int zeropad; | |
3936 char_u base; | |
3937 char_u opt; | |
3938 #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
|
3939 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
|
3940 char_u win_tmp[TMPLEN]; |
678 | 3941 char_u *usefmt = fmt; |
681 | 3942 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
|
3943 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
|
3944 int save_redr_type = curwin->w_redr_type; |
678 | 3945 |
3946 #ifdef FEAT_EVAL | |
3947 /* | |
3948 * When the format starts with "%!" then evaluate it as an expression and | |
3949 * use the result as the actual format string. | |
3950 */ | |
3951 if (fmt[0] == '%' && fmt[1] == '!') | |
3952 { | |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
3953 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
|
3954 |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
3955 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
|
3956 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
|
3957 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
|
3958 |
678 | 3959 usefmt = eval_to_string_safe(fmt + 2, NULL, use_sandbox); |
3960 if (usefmt == NULL) | |
943 | 3961 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
|
3962 |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
3963 do_unlet((char_u *)"g:statusline_winid", TRUE); |
678 | 3964 } |
3965 #endif | |
7 | 3966 |
3967 if (fillchar == 0) | |
3968 fillchar = ' '; | |
819 | 3969 /* Can't handle a multi-byte fill character yet. */ |
3970 else if (mb_char2len(fillchar) > 1) | |
3971 fillchar = '-'; | |
3972 | |
15557
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3973 // 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
|
3974 // 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
|
3975 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
|
3976 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
|
3977 { |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3978 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
|
3979 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
|
3980 } |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3981 |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3982 // 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
|
3983 // 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
|
3984 p = ml_get_buf(wp->w_buffer, lnum, FALSE); |
4333 | 3985 empty_line = (*p == NUL); |
3986 | |
15557
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3987 // 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
|
3988 // 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
|
3989 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
|
3990 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
|
3991 { |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3992 // 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
|
3993 // 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
|
3994 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
|
3995 wp->w_cursor.coladd = 0; |
4333 | 3996 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
|
3997 } |
4333 | 3998 else |
3999 byteval = (*mb_ptr2char)(p + wp->w_cursor.col); | |
7 | 4000 |
4001 groupdepth = 0; | |
4002 p = out; | |
4003 curitem = 0; | |
4004 prevchar_isflag = TRUE; | |
4005 prevchar_isitem = FALSE; | |
678 | 4006 for (s = usefmt; *s; ) |
7 | 4007 { |
2704 | 4008 if (curitem == STL_MAX_ITEM) |
4009 { | |
4010 /* There are too many items. Add the error code to the statusline | |
4011 * to give the user a hint about what went wrong. */ | |
4012 if (p + 6 < out + outlen) | |
4013 { | |
4014 mch_memmove(p, " E541", (size_t)5); | |
4015 p += 5; | |
4016 } | |
4017 break; | |
4018 } | |
4019 | |
7 | 4020 if (*s != NUL && *s != '%') |
4021 prevchar_isflag = prevchar_isitem = FALSE; | |
4022 | |
4023 /* | |
4024 * Handle up to the next '%' or the end. | |
4025 */ | |
4026 while (*s != NUL && *s != '%' && p + 1 < out + outlen) | |
4027 *p++ = *s++; | |
4028 if (*s == NUL || p + 1 >= out + outlen) | |
4029 break; | |
4030 | |
4031 /* | |
4032 * Handle one '%' item. | |
4033 */ | |
4034 s++; | |
2694 | 4035 if (*s == NUL) /* ignore trailing % */ |
4036 break; | |
7 | 4037 if (*s == '%') |
4038 { | |
4039 if (p + 1 >= out + outlen) | |
4040 break; | |
4041 *p++ = *s++; | |
4042 prevchar_isflag = prevchar_isitem = FALSE; | |
4043 continue; | |
4044 } | |
4045 if (*s == STL_MIDDLEMARK) | |
4046 { | |
4047 s++; | |
4048 if (groupdepth > 0) | |
4049 continue; | |
4050 item[curitem].type = Middle; | |
4051 item[curitem++].start = p; | |
4052 continue; | |
4053 } | |
4054 if (*s == STL_TRUNCMARK) | |
4055 { | |
4056 s++; | |
4057 item[curitem].type = Trunc; | |
4058 item[curitem++].start = p; | |
4059 continue; | |
4060 } | |
4061 if (*s == ')') | |
4062 { | |
4063 s++; | |
4064 if (groupdepth < 1) | |
4065 continue; | |
4066 groupdepth--; | |
4067 | |
4068 t = item[groupitem[groupdepth]].start; | |
4069 *p = NUL; | |
4070 l = vim_strsize(t); | |
4071 if (curitem > groupitem[groupdepth] + 1 | |
4072 && item[groupitem[groupdepth]].minwid == 0) | |
4073 { | |
12660
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4074 /* remove group if all items are empty and highlight group |
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4075 * doesn't change */ |
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4076 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
|
4077 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
|
4078 { |
12660
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4079 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
|
4080 { |
185f8dbdcf26
patch 8.0.1220: skipping empty statusline groups is not correct
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
4081 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
|
4082 break; |
185f8dbdcf26
patch 8.0.1220: skipping empty statusline groups is not correct
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
4083 } |
185f8dbdcf26
patch 8.0.1220: skipping empty statusline groups is not correct
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
4084 } |
7 | 4085 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
|
4086 { |
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4087 if (item[n].type == Normal) |
7 | 4088 break; |
12660
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4089 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
|
4090 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
|
4091 } |
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4092 if (n == curitem && group_start_userhl == group_end_userhl) |
7 | 4093 { |
4094 p = t; | |
4095 l = 0; | |
4096 } | |
4097 } | |
4098 if (l > item[groupitem[groupdepth]].maxwid) | |
4099 { | |
4100 /* truncate, remove n bytes of text at the start */ | |
4101 if (has_mbyte) | |
4102 { | |
4103 /* Find the first character that should be included. */ | |
4104 n = 0; | |
4105 while (l >= item[groupitem[groupdepth]].maxwid) | |
4106 { | |
4107 l -= ptr2cells(t + n); | |
474 | 4108 n += (*mb_ptr2len)(t + n); |
7 | 4109 } |
4110 } | |
4111 else | |
835 | 4112 n = (long)(p - t) - item[groupitem[groupdepth]].maxwid + 1; |
7 | 4113 |
4114 *t = '<'; | |
1869 | 4115 mch_memmove(t + 1, t + n, (size_t)(p - (t + n))); |
7 | 4116 p = p - n + 1; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15557
diff
changeset
|
4117 |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15557
diff
changeset
|
4118 // Fill up space left over by half a double-wide char. |
7 | 4119 while (++l < item[groupitem[groupdepth]].minwid) |
4120 *p++ = fillchar; | |
4121 | |
4122 /* correct the start of the items for the truncation */ | |
4123 for (l = groupitem[groupdepth] + 1; l < curitem; l++) | |
4124 { | |
4125 item[l].start -= n; | |
4126 if (item[l].start < t) | |
4127 item[l].start = t; | |
4128 } | |
4129 } | |
4130 else if (abs(item[groupitem[groupdepth]].minwid) > l) | |
4131 { | |
4132 /* fill */ | |
4133 n = item[groupitem[groupdepth]].minwid; | |
4134 if (n < 0) | |
4135 { | |
4136 /* fill by appending characters */ | |
4137 n = 0 - n; | |
4138 while (l++ < n && p + 1 < out + outlen) | |
4139 *p++ = fillchar; | |
4140 } | |
4141 else | |
4142 { | |
4143 /* fill by inserting characters */ | |
1869 | 4144 mch_memmove(t + n - l, t, (size_t)(p - t)); |
7 | 4145 l = n - l; |
4146 if (p + l >= out + outlen) | |
835 | 4147 l = (long)((out + outlen) - p - 1); |
7 | 4148 p += l; |
4149 for (n = groupitem[groupdepth] + 1; n < curitem; n++) | |
4150 item[n].start += l; | |
4151 for ( ; l > 0; l--) | |
4152 *t++ = fillchar; | |
4153 } | |
4154 } | |
4155 continue; | |
4156 } | |
4157 minwid = 0; | |
4158 maxwid = 9999; | |
4159 zeropad = FALSE; | |
4160 l = 1; | |
4161 if (*s == '0') | |
4162 { | |
4163 s++; | |
4164 zeropad = TRUE; | |
4165 } | |
4166 if (*s == '-') | |
4167 { | |
4168 s++; | |
4169 l = -1; | |
4170 } | |
4171 if (VIM_ISDIGIT(*s)) | |
4172 { | |
4173 minwid = (int)getdigits(&s); | |
4174 if (minwid < 0) /* overflow */ | |
4175 minwid = 0; | |
4176 } | |
678 | 4177 if (*s == STL_USER_HL) |
7 | 4178 { |
4179 item[curitem].type = Highlight; | |
4180 item[curitem].start = p; | |
4181 item[curitem].minwid = minwid > 9 ? 1 : minwid; | |
4182 s++; | |
4183 curitem++; | |
4184 continue; | |
4185 } | |
681 | 4186 if (*s == STL_TABPAGENR || *s == STL_TABCLOSENR) |
4187 { | |
4188 if (*s == STL_TABCLOSENR) | |
4189 { | |
4190 if (minwid == 0) | |
4191 { | |
4192 /* %X ends the close label, go back to the previously | |
4193 * define tab label nr. */ | |
4194 for (n = curitem - 1; n >= 0; --n) | |
4195 if (item[n].type == TabPage && item[n].minwid >= 0) | |
4196 { | |
4197 minwid = item[n].minwid; | |
4198 break; | |
4199 } | |
4200 } | |
4201 else | |
4202 /* close nrs are stored as negative values */ | |
4203 minwid = - minwid; | |
4204 } | |
4205 item[curitem].type = TabPage; | |
4206 item[curitem].start = p; | |
4207 item[curitem].minwid = minwid; | |
4208 s++; | |
4209 curitem++; | |
4210 continue; | |
4211 } | |
7 | 4212 if (*s == '.') |
4213 { | |
4214 s++; | |
4215 if (VIM_ISDIGIT(*s)) | |
4216 { | |
4217 maxwid = (int)getdigits(&s); | |
4218 if (maxwid <= 0) /* overflow */ | |
4219 maxwid = 50; | |
4220 } | |
4221 } | |
4222 minwid = (minwid > 50 ? 50 : minwid) * l; | |
4223 if (*s == '(') | |
4224 { | |
4225 groupitem[groupdepth++] = curitem; | |
4226 item[curitem].type = Group; | |
4227 item[curitem].start = p; | |
4228 item[curitem].minwid = minwid; | |
4229 item[curitem].maxwid = maxwid; | |
4230 s++; | |
4231 curitem++; | |
4232 continue; | |
4233 } | |
4234 if (vim_strchr(STL_ALL, *s) == NULL) | |
4235 { | |
4236 s++; | |
4237 continue; | |
4238 } | |
4239 opt = *s++; | |
4240 | |
4241 /* OK - now for the real work */ | |
4242 base = 'D'; | |
4243 itemisflag = FALSE; | |
4244 fillable = TRUE; | |
4245 num = -1; | |
4246 str = NULL; | |
4247 switch (opt) | |
4248 { | |
4249 case STL_FILEPATH: | |
4250 case STL_FULLPATH: | |
4251 case STL_FILENAME: | |
4252 fillable = FALSE; /* don't change ' ' to fillchar */ | |
4253 if (buf_spname(wp->w_buffer) != NULL) | |
3839 | 4254 vim_strncpy(NameBuff, buf_spname(wp->w_buffer), MAXPATHL - 1); |
7 | 4255 else |
4256 { | |
4257 t = (opt == STL_FULLPATH) ? wp->w_buffer->b_ffname | |
667 | 4258 : wp->w_buffer->b_fname; |
7 | 4259 home_replace(wp->w_buffer, t, NameBuff, MAXPATHL, TRUE); |
4260 } | |
4261 trans_characters(NameBuff, MAXPATHL); | |
4262 if (opt != STL_FILENAME) | |
4263 str = NameBuff; | |
4264 else | |
4265 str = gettail(NameBuff); | |
4266 break; | |
4267 | |
4268 case STL_VIM_EXPR: /* '{' */ | |
4269 itemisflag = TRUE; | |
4270 t = p; | |
4271 while (*s != '}' && *s != NUL && p + 1 < out + outlen) | |
4272 *p++ = *s++; | |
4273 if (*s != '}') /* missing '}' or out of space */ | |
4274 break; | |
4275 s++; | |
4276 *p = 0; | |
4277 p = t; | |
4278 | |
4279 #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
|
4280 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
|
4281 "%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
|
4282 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
|
4283 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
|
4284 set_internal_string_var((char_u *)"g:actual_curwin", win_tmp); |
7 | 4285 |
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
|
4286 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
|
4287 save_curwin = curwin; |
7 | 4288 curwin = wp; |
4289 curbuf = wp->w_buffer; | |
4290 | |
675 | 4291 str = eval_to_string_safe(p, &t, use_sandbox); |
7 | 4292 |
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
|
4293 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
|
4294 curbuf = save_curbuf; |
145 | 4295 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
|
4296 do_unlet((char_u *)"g:actual_curwin", TRUE); |
7 | 4297 |
4298 if (str != NULL && *str != 0) | |
4299 { | |
4300 if (*skipdigits(str) == NUL) | |
4301 { | |
4302 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
|
4303 VIM_CLEAR(str); |
7 | 4304 itemisflag = FALSE; |
4305 } | |
4306 } | |
4307 #endif | |
4308 break; | |
4309 | |
4310 case STL_LINE: | |
4311 num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) | |
4312 ? 0L : (long)(wp->w_cursor.lnum); | |
4313 break; | |
4314 | |
4315 case STL_NUMLINES: | |
4316 num = wp->w_buffer->b_ml.ml_line_count; | |
4317 break; | |
4318 | |
4319 case STL_COLUMN: | |
4320 num = !(State & INSERT) && empty_line | |
4321 ? 0 : (int)wp->w_cursor.col + 1; | |
4322 break; | |
4323 | |
4324 case STL_VIRTCOL: | |
4325 case STL_VIRTCOL_ALT: | |
4326 /* In list mode virtcol needs to be recomputed */ | |
4327 virtcol = wp->w_virtcol; | |
4328 if (wp->w_p_list && lcs_tab1 == NUL) | |
4329 { | |
4330 wp->w_p_list = FALSE; | |
4331 getvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); | |
4332 wp->w_p_list = TRUE; | |
4333 } | |
4334 ++virtcol; | |
4335 /* Don't display %V if it's the same as %c. */ | |
4336 if (opt == STL_VIRTCOL_ALT | |
4337 && (virtcol == (colnr_T)(!(State & INSERT) && empty_line | |
4338 ? 0 : (int)wp->w_cursor.col + 1))) | |
4339 break; | |
4340 num = (long)virtcol; | |
4341 break; | |
4342 | |
4343 case STL_PERCENTAGE: | |
4344 num = (int)(((long)wp->w_cursor.lnum * 100L) / | |
4345 (long)wp->w_buffer->b_ml.ml_line_count); | |
4346 break; | |
4347 | |
4348 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
|
4349 str = buf_tmp; |
1869 | 4350 get_rel_pos(wp, str, TMPLEN); |
7 | 4351 break; |
4352 | |
4353 case STL_ARGLISTSTAT: | |
4354 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
|
4355 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
|
4356 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
|
4357 str = buf_tmp; |
7 | 4358 break; |
4359 | |
4360 case STL_KEYMAP: | |
4361 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
|
4362 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
|
4363 str = buf_tmp; |
7 | 4364 break; |
4365 case STL_PAGENUM: | |
706 | 4366 #if defined(FEAT_PRINTER) || defined(FEAT_GUI_TABLINE) |
686 | 4367 num = printer_page_num; |
7 | 4368 #else |
4369 num = 0; | |
4370 #endif | |
4371 break; | |
4372 | |
4373 case STL_BUFNO: | |
4374 num = wp->w_buffer->b_fnum; | |
4375 break; | |
4376 | |
4377 case STL_OFFSET_X: | |
4378 base = 'X'; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12660
diff
changeset
|
4379 /* FALLTHROUGH */ |
7 | 4380 case STL_OFFSET: |
4381 #ifdef FEAT_BYTEOFF | |
4382 l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL); | |
4383 num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ? | |
4384 0L : l + 1 + (!(State & INSERT) && empty_line ? | |
4385 0 : (int)wp->w_cursor.col); | |
4386 #endif | |
4387 break; | |
4388 | |
4389 case STL_BYTEVAL_X: | |
4390 base = 'X'; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12660
diff
changeset
|
4391 /* FALLTHROUGH */ |
7 | 4392 case STL_BYTEVAL: |
4333 | 4393 num = byteval; |
7 | 4394 if (num == NL) |
4395 num = 0; | |
4396 else if (num == CAR && get_fileformat(wp->w_buffer) == EOL_MAC) | |
4397 num = NL; | |
4398 break; | |
4399 | |
4400 case STL_ROFLAG: | |
4401 case STL_ROFLAG_ALT: | |
4402 itemisflag = TRUE; | |
4403 if (wp->w_buffer->b_p_ro) | |
4795
8360a59aa04b
updated for version 7.3.1144
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
4404 str = (char_u *)((opt == STL_ROFLAG_ALT) ? ",RO" : _("[RO]")); |
7 | 4405 break; |
4406 | |
4407 case STL_HELPFLAG: | |
4408 case STL_HELPFLAG_ALT: | |
4409 itemisflag = TRUE; | |
4410 if (wp->w_buffer->b_help) | |
4411 str = (char_u *)((opt == STL_HELPFLAG_ALT) ? ",HLP" | |
809 | 4412 : _("[Help]")); |
7 | 4413 break; |
4414 | |
4415 case STL_FILETYPE: | |
4416 if (*wp->w_buffer->b_p_ft != NUL | |
4417 && STRLEN(wp->w_buffer->b_p_ft) < TMPLEN - 3) | |
4418 { | |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4419 vim_snprintf((char *)buf_tmp, sizeof(buf_tmp), "[%s]", |
272 | 4420 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
|
4421 str = buf_tmp; |
7 | 4422 } |
4423 break; | |
4424 | |
4425 case STL_FILETYPE_ALT: | |
4426 itemisflag = TRUE; | |
4427 if (*wp->w_buffer->b_p_ft != NUL | |
4428 && STRLEN(wp->w_buffer->b_p_ft) < TMPLEN - 2) | |
4429 { | |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4430 vim_snprintf((char *)buf_tmp, sizeof(buf_tmp), ",%s", |
272 | 4431 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
|
4432 for (t = buf_tmp; *t != 0; t++) |
7 | 4433 *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
|
4434 str = buf_tmp; |
7 | 4435 } |
4436 break; | |
4437 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
4438 #if defined(FEAT_QUICKFIX) |
7 | 4439 case STL_PREVIEWFLAG: |
4440 case STL_PREVIEWFLAG_ALT: | |
4441 itemisflag = TRUE; | |
4442 if (wp->w_p_pvw) | |
4443 str = (char_u *)((opt == STL_PREVIEWFLAG_ALT) ? ",PRV" | |
4444 : _("[Preview]")); | |
4445 break; | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4446 |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4447 case STL_QUICKFIX: |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4448 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
|
4449 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
|
4450 ? _(msg_loclist) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4451 : _(msg_qflist)); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4452 break; |
7 | 4453 #endif |
4454 | |
4455 case STL_MODIFIED: | |
4456 case STL_MODIFIED_ALT: | |
4457 itemisflag = TRUE; | |
4458 switch ((opt == STL_MODIFIED_ALT) | |
4459 + bufIsChanged(wp->w_buffer) * 2 | |
4460 + (!wp->w_buffer->b_p_ma) * 4) | |
4461 { | |
4462 case 2: str = (char_u *)"[+]"; break; | |
4463 case 3: str = (char_u *)",+"; break; | |
4464 case 4: str = (char_u *)"[-]"; break; | |
4465 case 5: str = (char_u *)",-"; break; | |
4466 case 6: str = (char_u *)"[+-]"; break; | |
4467 case 7: str = (char_u *)",+-"; break; | |
4468 } | |
4469 break; | |
678 | 4470 |
4471 case STL_HIGHLIGHT: | |
4472 t = s; | |
4473 while (*s != '#' && *s != NUL) | |
4474 ++s; | |
4475 if (*s == '#') | |
4476 { | |
4477 item[curitem].type = Highlight; | |
4478 item[curitem].start = p; | |
835 | 4479 item[curitem].minwid = -syn_namen2id(t, (int)(s - t)); |
678 | 4480 curitem++; |
4481 } | |
5407 | 4482 if (*s != NUL) |
4483 ++s; | |
678 | 4484 continue; |
7 | 4485 } |
4486 | |
4487 item[curitem].start = p; | |
4488 item[curitem].type = Normal; | |
4489 if (str != NULL && *str) | |
4490 { | |
4491 t = str; | |
4492 if (itemisflag) | |
4493 { | |
4494 if ((t[0] && t[1]) | |
4495 && ((!prevchar_isitem && *t == ',') | |
4496 || (prevchar_isflag && *t == ' '))) | |
4497 t++; | |
4498 prevchar_isflag = TRUE; | |
4499 } | |
4500 l = vim_strsize(t); | |
4501 if (l > 0) | |
4502 prevchar_isitem = TRUE; | |
4503 if (l > maxwid) | |
4504 { | |
4505 while (l >= maxwid) | |
4506 if (has_mbyte) | |
4507 { | |
4508 l -= ptr2cells(t); | |
474 | 4509 t += (*mb_ptr2len)(t); |
7 | 4510 } |
4511 else | |
4512 l -= byte2cells(*t++); | |
4513 if (p + 1 >= out + outlen) | |
4514 break; | |
4515 *p++ = '<'; | |
4516 } | |
4517 if (minwid > 0) | |
4518 { | |
4519 for (; l < minwid && p + 1 < out + outlen; l++) | |
4520 { | |
4521 /* Don't put a "-" in front of a digit. */ | |
4522 if (l + 1 == minwid && fillchar == '-' && VIM_ISDIGIT(*t)) | |
4523 *p++ = ' '; | |
4524 else | |
4525 *p++ = fillchar; | |
4526 } | |
4527 minwid = 0; | |
4528 } | |
4529 else | |
4530 minwid *= -1; | |
4531 while (*t && p + 1 < out + outlen) | |
4532 { | |
4533 *p++ = *t++; | |
4534 /* Change a space by fillchar, unless fillchar is '-' and a | |
4535 * digit follows. */ | |
4536 if (fillable && p[-1] == ' ' | |
4537 && (!VIM_ISDIGIT(*t) || fillchar != '-')) | |
4538 p[-1] = fillchar; | |
4539 } | |
4540 for (; l < minwid && p + 1 < out + outlen; l++) | |
4541 *p++ = fillchar; | |
4542 } | |
4543 else if (num >= 0) | |
4544 { | |
4545 int nbase = (base == 'D' ? 10 : (base == 'O' ? 8 : 16)); | |
4546 char_u nstr[20]; | |
4547 | |
4548 if (p + 20 >= out + outlen) | |
4549 break; /* not sufficient space */ | |
4550 prevchar_isitem = TRUE; | |
4551 t = nstr; | |
4552 if (opt == STL_VIRTCOL_ALT) | |
4553 { | |
4554 *t++ = '-'; | |
4555 minwid--; | |
4556 } | |
4557 *t++ = '%'; | |
4558 if (zeropad) | |
4559 *t++ = '0'; | |
4560 *t++ = '*'; | |
1869 | 4561 *t++ = nbase == 16 ? base : (char_u)(nbase == 8 ? 'o' : 'd'); |
7 | 4562 *t = 0; |
4563 | |
4564 for (n = num, l = 1; n >= nbase; n /= nbase) | |
4565 l++; | |
4566 if (opt == STL_VIRTCOL_ALT) | |
4567 l++; | |
4568 if (l > maxwid) | |
4569 { | |
4570 l += 2; | |
4571 n = l - maxwid; | |
4572 while (l-- > maxwid) | |
4573 num /= nbase; | |
4574 *t++ = '>'; | |
4575 *t++ = '%'; | |
4576 *t = t[-3]; | |
4577 *++t = 0; | |
272 | 4578 vim_snprintf((char *)p, outlen - (p - out), (char *)nstr, |
4579 0, num, n); | |
7 | 4580 } |
4581 else | |
272 | 4582 vim_snprintf((char *)p, outlen - (p - out), (char *)nstr, |
4583 minwid, num); | |
7 | 4584 p += STRLEN(p); |
4585 } | |
4586 else | |
4587 item[curitem].type = Empty; | |
4588 | |
4589 if (opt == STL_VIM_EXPR) | |
4590 vim_free(str); | |
4591 | |
4592 if (num >= 0 || (!itemisflag && str && *str)) | |
4593 prevchar_isflag = FALSE; /* Item not NULL, but not a flag */ | |
4594 curitem++; | |
4595 } | |
4596 *p = NUL; | |
4597 itemcnt = curitem; | |
4598 | |
678 | 4599 #ifdef FEAT_EVAL |
4600 if (usefmt != fmt) | |
4601 vim_free(usefmt); | |
4602 #endif | |
4603 | |
7 | 4604 width = vim_strsize(out); |
4605 if (maxwidth > 0 && width > maxwidth) | |
4606 { | |
1736 | 4607 /* Result is too long, must truncate somewhere. */ |
7 | 4608 l = 0; |
4609 if (itemcnt == 0) | |
4610 s = out; | |
4611 else | |
4612 { | |
4613 for ( ; l < itemcnt; l++) | |
4614 if (item[l].type == Trunc) | |
4615 { | |
4616 /* Truncate at %< item. */ | |
4617 s = item[l].start; | |
4618 break; | |
4619 } | |
4620 if (l == itemcnt) | |
4621 { | |
4622 /* No %< item, truncate first item. */ | |
4623 s = item[0].start; | |
4624 l = 0; | |
4625 } | |
4626 } | |
4627 | |
4628 if (width - vim_strsize(s) >= maxwidth) | |
4629 { | |
4630 /* Truncation mark is beyond max length */ | |
4631 if (has_mbyte) | |
4632 { | |
4633 s = out; | |
4634 width = 0; | |
4635 for (;;) | |
4636 { | |
4637 width += ptr2cells(s); | |
4638 if (width >= maxwidth) | |
4639 break; | |
474 | 4640 s += (*mb_ptr2len)(s); |
7 | 4641 } |
4642 /* Fill up for half a double-wide character. */ | |
4643 while (++width < maxwidth) | |
4644 *s++ = fillchar; | |
4645 } | |
4646 else | |
4647 s = out + maxwidth - 1; | |
4648 for (l = 0; l < itemcnt; l++) | |
4649 if (item[l].start > s) | |
4650 break; | |
4651 itemcnt = l; | |
4652 *s++ = '>'; | |
4653 *s = 0; | |
4654 } | |
4655 else | |
4656 { | |
4657 if (has_mbyte) | |
4658 { | |
4659 n = 0; | |
4660 while (width >= maxwidth) | |
4661 { | |
4662 width -= ptr2cells(s + n); | |
474 | 4663 n += (*mb_ptr2len)(s + n); |
7 | 4664 } |
4665 } | |
4666 else | |
4667 n = width - maxwidth + 1; | |
4668 p = s + n; | |
1618 | 4669 STRMOVE(s + 1, p); |
7 | 4670 *s = '<'; |
4671 | |
4672 /* Fill up for half a double-wide character. */ | |
4673 while (++width < maxwidth) | |
4674 { | |
4675 s = s + STRLEN(s); | |
4676 *s++ = fillchar; | |
4677 *s = NUL; | |
4678 } | |
4679 | |
4680 --n; /* count the '<' */ | |
4681 for (; l < itemcnt; l++) | |
4682 { | |
4683 if (item[l].start - n >= s) | |
4684 item[l].start -= n; | |
4685 else | |
4686 item[l].start = s; | |
4687 } | |
4688 } | |
4689 width = maxwidth; | |
4690 } | |
4691 else if (width < maxwidth && STRLEN(out) + maxwidth - width + 1 < outlen) | |
4692 { | |
4693 /* Apply STL_MIDDLE if any */ | |
4694 for (l = 0; l < itemcnt; l++) | |
4695 if (item[l].type == Middle) | |
4696 break; | |
4697 if (l < itemcnt) | |
4698 { | |
4699 p = item[l].start + maxwidth - width; | |
1618 | 4700 STRMOVE(p, item[l].start); |
7 | 4701 for (s = item[l].start; s < p; s++) |
4702 *s = fillchar; | |
4703 for (l++; l < itemcnt; l++) | |
4704 item[l].start += maxwidth - width; | |
4705 width = maxwidth; | |
4706 } | |
4707 } | |
4708 | |
681 | 4709 /* Store the info about highlighting. */ |
4710 if (hltab != NULL) | |
7 | 4711 { |
681 | 4712 sp = hltab; |
7 | 4713 for (l = 0; l < itemcnt; l++) |
4714 { | |
4715 if (item[l].type == Highlight) | |
4716 { | |
681 | 4717 sp->start = item[l].start; |
4718 sp->userhl = item[l].minwid; | |
4719 sp++; | |
7 | 4720 } |
4721 } | |
681 | 4722 sp->start = NULL; |
4723 sp->userhl = 0; | |
4724 } | |
4725 | |
4726 /* Store the info about tab pages labels. */ | |
4727 if (tabtab != NULL) | |
4728 { | |
4729 sp = tabtab; | |
4730 for (l = 0; l < itemcnt; l++) | |
4731 { | |
4732 if (item[l].type == TabPage) | |
4733 { | |
4734 sp->start = item[l].start; | |
4735 sp->userhl = item[l].minwid; | |
4736 sp++; | |
4737 } | |
4738 } | |
4739 sp->start = NULL; | |
4740 sp->userhl = 0; | |
7 | 4741 } |
4742 | |
12572
31737ff54115
patch 8.0.1164: changing StatusLine highlight does not always work
Christian Brabandt <cb@256bit.org>
parents:
12479
diff
changeset
|
4743 /* When inside update_screen we do not want redrawing a stausline, ruler, |
31737ff54115
patch 8.0.1164: changing StatusLine highlight does not always work
Christian Brabandt <cb@256bit.org>
parents:
12479
diff
changeset
|
4744 * title, etc. to trigger another redraw, it may cause an endless loop. */ |
31737ff54115
patch 8.0.1164: changing StatusLine highlight does not always work
Christian Brabandt <cb@256bit.org>
parents:
12479
diff
changeset
|
4745 if (updating_screen) |
31737ff54115
patch 8.0.1164: changing StatusLine highlight does not always work
Christian Brabandt <cb@256bit.org>
parents:
12479
diff
changeset
|
4746 { |
31737ff54115
patch 8.0.1164: changing StatusLine highlight does not always work
Christian Brabandt <cb@256bit.org>
parents:
12479
diff
changeset
|
4747 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
|
4748 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
|
4749 } |
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
|
4750 |
7 | 4751 return width; |
4752 } | |
4753 #endif /* FEAT_STL_OPT */ | |
4754 | |
686 | 4755 #if defined(FEAT_STL_OPT) || defined(FEAT_CMDL_INFO) \ |
4756 || defined(FEAT_GUI_TABLINE) || defined(PROTO) | |
7 | 4757 /* |
1869 | 4758 * Get relative cursor position in window into "buf[buflen]", in the form 99%, |
4759 * using "Top", "Bot" or "All" when appropriate. | |
7 | 4760 */ |
4761 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4762 get_rel_pos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4763 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4764 char_u *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4765 int buflen) |
7 | 4766 { |
4767 long above; /* number of lines above window */ | |
4768 long below; /* number of lines below window */ | |
4769 | |
6466 | 4770 if (buflen < 3) /* need at least 3 chars for writing */ |
4771 return; | |
7 | 4772 above = wp->w_topline - 1; |
4773 #ifdef FEAT_DIFF | |
4774 above += diff_check_fill(wp, wp->w_topline) - wp->w_topfill; | |
6975 | 4775 if (wp->w_topline == 1 && wp->w_topfill >= 1) |
4776 above = 0; /* All buffer lines are displayed and there is an | |
4777 * indication of filler lines, that can be considered | |
4778 * seeing all lines. */ | |
7 | 4779 #endif |
4780 below = wp->w_buffer->b_ml.ml_line_count - wp->w_botline + 1; | |
4781 if (below <= 0) | |
1869 | 4782 vim_strncpy(buf, (char_u *)(above == 0 ? _("All") : _("Bot")), |
4783 (size_t)(buflen - 1)); | |
7 | 4784 else if (above <= 0) |
1869 | 4785 vim_strncpy(buf, (char_u *)_("Top"), (size_t)(buflen - 1)); |
7 | 4786 else |
1869 | 4787 vim_snprintf((char *)buf, (size_t)buflen, "%2d%%", above > 1000000L |
7 | 4788 ? (int)(above / ((above + below) / 100L)) |
4789 : (int)(above * 100L / (above + below))); | |
4790 } | |
4791 #endif | |
4792 | |
4793 /* | |
1869 | 4794 * Append (file 2 of 8) to "buf[buflen]", if editing more than one file. |
7 | 4795 * Return TRUE if it was appended. |
4796 */ | |
1869 | 4797 static int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4798 append_arg_number( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4799 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4800 char_u *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4801 int buflen, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4802 int add_file) /* Add "file" before the arg number */ |
7 | 4803 { |
4804 char_u *p; | |
4805 | |
4806 if (ARGCOUNT <= 1) /* nothing to do */ | |
4807 return FALSE; | |
4808 | |
1869 | 4809 p = buf + STRLEN(buf); /* go to the end of the buffer */ |
4810 if (p - buf + 35 >= buflen) /* getting too long */ | |
7 | 4811 return FALSE; |
4812 *p++ = ' '; | |
4813 *p++ = '('; | |
4814 if (add_file) | |
4815 { | |
4816 STRCPY(p, "file "); | |
4817 p += 5; | |
4818 } | |
1869 | 4819 vim_snprintf((char *)p, (size_t)(buflen - (p - buf)), |
4820 wp->w_arg_idx_invalid ? "(%d) of %d)" | |
7 | 4821 : "%d of %d)", wp->w_arg_idx + 1, ARGCOUNT); |
4822 return TRUE; | |
4823 } | |
4824 | |
4825 /* | |
4826 * If fname is not a full path, make it a full path. | |
4827 * Returns pointer to allocated memory (NULL for failure). | |
4828 */ | |
4829 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4830 fix_fname(char_u *fname) |
7 | 4831 { |
4832 /* | |
4833 * Force expanding the path always for Unix, because symbolic links may | |
4834 * mess up the full path name, even though it starts with a '/'. | |
4835 * Also expand when there is ".." in the file name, try to remove it, | |
4836 * because "c:/src/../README" is equal to "c:/README". | |
1420 | 4837 * Similarly "c:/src//file" is equal to "c:/src/file". |
7 | 4838 * For MS-Windows also expand names like "longna~1" to "longname". |
4839 */ | |
1082 | 4840 #ifdef UNIX |
7 | 4841 return FullName_save(fname, TRUE); |
4842 #else | |
1420 | 4843 if (!vim_isAbsName(fname) |
4844 || strstr((char *)fname, "..") != NULL | |
4845 || strstr((char *)fname, "//") != NULL | |
4846 # ifdef BACKSLASH_IN_FILENAME | |
4847 || strstr((char *)fname, "\\\\") != NULL | |
4848 # endif | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
4849 # if defined(MSWIN) |
7 | 4850 || vim_strchr(fname, '~') != NULL |
1420 | 4851 # endif |
7 | 4852 ) |
4853 return FullName_save(fname, FALSE); | |
4854 | |
4855 fname = vim_strsave(fname); | |
4856 | |
1420 | 4857 # ifdef USE_FNAME_CASE |
15794
0d8291665b59
patch 8.1.0904: USE_LONG_FNAME never defined
Bram Moolenaar <Bram@vim.org>
parents:
15774
diff
changeset
|
4858 if (fname != NULL) |
0d8291665b59
patch 8.1.0904: USE_LONG_FNAME never defined
Bram Moolenaar <Bram@vim.org>
parents:
15774
diff
changeset
|
4859 fname_case(fname, 0); /* set correct case for file name */ |
1420 | 4860 # endif |
7 | 4861 |
4862 return fname; | |
4863 #endif | |
4864 } | |
4865 | |
4866 /* | |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
4867 * 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
|
4868 * "*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
|
4869 * 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
|
4870 * allocated memory. |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
4871 * The "*ffname" and "*sfname" pointer values on call will not be freed. |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
4872 * Note that the resulting "*ffname" pointer should be considered not allocaed. |
7 | 4873 */ |
4874 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4875 fname_expand( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4876 buf_T *buf UNUSED, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4877 char_u **ffname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4878 char_u **sfname) |
7 | 4879 { |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
4880 if (*ffname == NULL) // no file name given, nothing to do |
7 | 4881 return; |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
4882 if (*sfname == NULL) // no short file name given, use ffname |
7 | 4883 *sfname = *ffname; |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
4884 *ffname = fix_fname(*ffname); // expand to full path |
7 | 4885 |
4886 #ifdef FEAT_SHORTCUT | |
4887 if (!buf->b_p_bin) | |
4888 { | |
844 | 4889 char_u *rfname; |
7 | 4890 |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
4891 // 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
|
4892 rfname = mch_resolve_path(*ffname, FALSE); |
844 | 4893 if (rfname != NULL) |
7 | 4894 { |
4895 vim_free(*ffname); | |
4896 *ffname = rfname; | |
4897 *sfname = rfname; | |
4898 } | |
4899 } | |
4900 #endif | |
4901 } | |
4902 | |
4903 /* | |
4904 * Open a window for a number of buffers. | |
4905 */ | |
4906 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4907 ex_buffer_all(exarg_T *eap) |
7 | 4908 { |
4909 buf_T *buf; | |
4910 win_T *wp, *wpnext; | |
4911 int split_ret = OK; | |
4912 int p_ea_save; | |
4913 int open_wins = 0; | |
4914 int r; | |
4915 int count; /* Maximum number of windows to open. */ | |
4916 int all; /* When TRUE also load inactive buffers. */ | |
698 | 4917 int had_tab = cmdmod.tab; |
4918 tabpage_T *tpnext; | |
7 | 4919 |
4920 if (eap->addr_count == 0) /* make as many windows as possible */ | |
4921 count = 9999; | |
4922 else | |
4923 count = eap->line2; /* make as many windows as specified */ | |
4924 if (eap->cmdidx == CMD_unhide || eap->cmdidx == CMD_sunhide) | |
4925 all = FALSE; | |
4926 else | |
4927 all = TRUE; | |
4928 | |
4929 setpcmark(); | |
4930 | |
4931 #ifdef FEAT_GUI | |
4932 need_mouse_correct = TRUE; | |
4933 #endif | |
4934 | |
4935 /* | |
4936 * Close superfluous windows (two windows for the same buffer). | |
4937 * Also close windows that are not full-width. | |
4938 */ | |
698 | 4939 if (had_tab > 0) |
4354 | 4940 goto_tabpage_tp(first_tabpage, TRUE, TRUE); |
698 | 4941 for (;;) |
7 | 4942 { |
698 | 4943 tpnext = curtab->tp_next; |
4944 for (wp = firstwin; wp != NULL; wp = wpnext) | |
7 | 4945 { |
698 | 4946 wpnext = wp->w_next; |
706 | 4947 if ((wp->w_buffer->b_nwindows > 1 |
698 | 4948 || ((cmdmod.split & WSP_VERT) |
4949 ? wp->w_height + wp->w_status_height < Rows - p_ch | |
706 | 4950 - tabline_height() |
698 | 4951 : 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
|
4952 || (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
|
4953 && !(wp->w_closing || wp->w_buffer->b_locked > 0)) |
698 | 4954 { |
4955 win_close(wp, FALSE); | |
4956 wpnext = firstwin; /* just in case an autocommand does | |
4957 something strange with windows */ | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
4958 tpnext = first_tabpage; /* start all over... */ |
698 | 4959 open_wins = 0; |
4960 } | |
4961 else | |
4962 ++open_wins; | |
7 | 4963 } |
698 | 4964 |
4965 /* Without the ":tab" modifier only do the current tab page. */ | |
4966 if (had_tab == 0 || tpnext == NULL) | |
4967 break; | |
4354 | 4968 goto_tabpage_tp(tpnext, TRUE, TRUE); |
7 | 4969 } |
4970 | |
4971 /* | |
4972 * Go through the buffer list. When a buffer doesn't have a window yet, | |
4973 * open one. Otherwise move the window to the right position. | |
4974 * Watch out for autocommands that delete buffers or windows! | |
4975 */ | |
4976 /* Don't execute Win/Buf Enter/Leave autocommands here. */ | |
4977 ++autocmd_no_enter; | |
4978 win_enter(lastwin, FALSE); | |
4979 ++autocmd_no_leave; | |
4980 for (buf = firstbuf; buf != NULL && open_wins < count; buf = buf->b_next) | |
4981 { | |
4982 /* Check if this buffer needs a window */ | |
4983 if ((!all && buf->b_ml.ml_mfp == NULL) || !buf->b_p_bl) | |
4984 continue; | |
4985 | |
701 | 4986 if (had_tab != 0) |
4987 { | |
4988 /* With the ":tab" modifier don't move the window. */ | |
4989 if (buf->b_nwindows > 0) | |
4990 wp = lastwin; /* buffer has a window, skip it */ | |
4991 else | |
4992 wp = NULL; | |
4993 } | |
4994 else | |
4995 { | |
4996 /* 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
|
4997 FOR_ALL_WINDOWS(wp) |
701 | 4998 if (wp->w_buffer == buf) |
4999 break; | |
5000 /* If the buffer already has a window, move it */ | |
5001 if (wp != NULL) | |
5002 win_move_after(wp, curwin); | |
5003 } | |
5004 | |
5005 if (wp == NULL && split_ret == OK) | |
7 | 5006 { |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5007 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5008 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5009 set_bufref(&bufref, buf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
5010 |
7 | 5011 /* Split the window and put the buffer in it */ |
5012 p_ea_save = p_ea; | |
5013 p_ea = TRUE; /* use space from all windows */ | |
5014 split_ret = win_split(0, WSP_ROOM | WSP_BELOW); | |
5015 ++open_wins; | |
5016 p_ea = p_ea_save; | |
5017 if (split_ret == FAIL) | |
5018 continue; | |
5019 | |
5020 /* Open the buffer in this window. */ | |
5021 swap_exists_action = SEA_DIALOG; | |
5022 set_curbuf(buf, DOBUF_GOTO); | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5023 if (!bufref_valid(&bufref)) |
20 | 5024 { |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5025 /* autocommands deleted the buffer!!! */ |
20 | 5026 swap_exists_action = SEA_NONE; |
7 | 5027 break; |
5028 } | |
5029 if (swap_exists_action == SEA_QUIT) | |
5030 { | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
5031 #if defined(FEAT_EVAL) |
24 | 5032 cleanup_T cs; |
5033 | |
5034 /* Reset the error/interrupt/exception state here so that | |
5035 * aborting() returns FALSE when closing a window. */ | |
5036 enter_cleanup(&cs); | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
5037 #endif |
24 | 5038 |
5039 /* User selected Quit at ATTENTION prompt; close this window. */ | |
7 | 5040 win_close(curwin, TRUE); |
5041 --open_wins; | |
5042 swap_exists_action = SEA_NONE; | |
602 | 5043 swap_exists_did_quit = TRUE; |
24 | 5044 |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
5045 #if defined(FEAT_EVAL) |
24 | 5046 /* Restore the error/interrupt/exception state if not |
5047 * discarded by a new aborting error, interrupt, or uncaught | |
5048 * exception. */ | |
5049 leave_cleanup(&cs); | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
5050 #endif |
7 | 5051 } |
5052 else | |
5053 handle_swap_exists(NULL); | |
5054 } | |
5055 | |
5056 ui_breakcheck(); | |
5057 if (got_int) | |
5058 { | |
5059 (void)vgetc(); /* only break the file loading, not the rest */ | |
5060 break; | |
5061 } | |
20 | 5062 #ifdef FEAT_EVAL |
5063 /* Autocommands deleted the buffer or aborted script processing!!! */ | |
5064 if (aborting()) | |
5065 break; | |
5066 #endif | |
698 | 5067 /* When ":tab" was used open a new tab for a new window repeatedly. */ |
5068 if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) | |
5069 cmdmod.tab = 9999; | |
7 | 5070 } |
5071 --autocmd_no_enter; | |
5072 win_enter(firstwin, FALSE); /* back to first window */ | |
5073 --autocmd_no_leave; | |
5074 | |
5075 /* | |
5076 * Close superfluous windows. | |
5077 */ | |
5078 for (wp = lastwin; open_wins > count; ) | |
5079 { | |
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
|
5080 r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer) |
7 | 5081 || autowrite(wp->w_buffer, FALSE) == OK); |
5082 if (!win_valid(wp)) | |
5083 { | |
5084 /* BufWrite Autocommands made the window invalid, start over */ | |
5085 wp = lastwin; | |
5086 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
5087 else if (r) |
7 | 5088 { |
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
|
5089 win_close(wp, !buf_hide(wp->w_buffer)); |
7 | 5090 --open_wins; |
5091 wp = lastwin; | |
5092 } | |
5093 else | |
5094 { | |
5095 wp = wp->w_prev; | |
5096 if (wp == NULL) | |
5097 break; | |
5098 } | |
5099 } | |
5100 } | |
5101 | |
5102 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
5103 static int chk_modeline(linenr_T, int); |
717 | 5104 |
7 | 5105 /* |
5106 * do_modelines() - process mode lines for the current file | |
5107 * | |
717 | 5108 * "flags" can be: |
5109 * OPT_WINONLY only set options local to window | |
5110 * OPT_NOWIN don't set options local to window | |
5111 * | |
7 | 5112 * Returns immediately if the "ml" option isn't set. |
5113 */ | |
5114 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5115 do_modelines(int flags) |
7 | 5116 { |
23 | 5117 linenr_T lnum; |
5118 int nmlines; | |
5119 static int entered = 0; | |
7 | 5120 |
5121 if (!curbuf->b_p_ml || (nmlines = (int)p_mls) == 0) | |
5122 return; | |
5123 | |
5124 /* Disallow recursive entry here. Can happen when executing a modeline | |
5125 * triggers an autocommand, which reloads modelines with a ":do". */ | |
5126 if (entered) | |
5127 return; | |
5128 | |
5129 ++entered; | |
5130 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count && lnum <= nmlines; | |
5131 ++lnum) | |
717 | 5132 if (chk_modeline(lnum, flags) == FAIL) |
7 | 5133 nmlines = 0; |
5134 | |
5135 for (lnum = curbuf->b_ml.ml_line_count; lnum > 0 && lnum > nmlines | |
5136 && lnum > curbuf->b_ml.ml_line_count - nmlines; --lnum) | |
717 | 5137 if (chk_modeline(lnum, flags) == FAIL) |
7 | 5138 nmlines = 0; |
5139 --entered; | |
5140 } | |
5141 | |
5142 #include "version.h" /* for version number */ | |
5143 | |
5144 /* | |
5145 * chk_modeline() - check a single line for a mode string | |
5146 * Return FAIL if an error encountered. | |
5147 */ | |
5148 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5149 chk_modeline( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5150 linenr_T lnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5151 int flags) /* Same as for do_modelines(). */ |
7 | 5152 { |
5153 char_u *s; | |
5154 char_u *e; | |
5155 char_u *linecopy; /* local copy of any modeline found */ | |
5156 int prev; | |
5157 int vers; | |
5158 int end; | |
5159 int retval = OK; | |
5160 char_u *save_sourcing_name; | |
5161 linenr_T save_sourcing_lnum; | |
5162 #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
|
5163 sctx_T save_current_sctx; |
7 | 5164 #endif |
5165 | |
5166 prev = -1; | |
5167 for (s = ml_get(lnum); *s != NUL; ++s) | |
5168 { | |
5169 if (prev == -1 || vim_isspace(prev)) | |
5170 { | |
5171 if ((prev != -1 && STRNCMP(s, "ex:", (size_t)3) == 0) | |
5172 || STRNCMP(s, "vi:", (size_t)3) == 0) | |
5173 break; | |
5010
b614332f7df2
updated for version 7.3.1249
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
5174 /* Accept both "vim" and "Vim". */ |
b614332f7df2
updated for version 7.3.1249
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
5175 if ((s[0] == 'v' || s[0] == 'V') && s[1] == 'i' && s[2] == 'm') |
7 | 5176 { |
5177 if (s[3] == '<' || s[3] == '=' || s[3] == '>') | |
5178 e = s + 4; | |
5179 else | |
5180 e = s + 3; | |
5181 vers = getdigits(&e); | |
5182 if (*e == ':' | |
5043
53c1b30632df
updated for version 7.3.1265
Bram Moolenaar <bram@vim.org>
parents:
5010
diff
changeset
|
5183 && (s[0] != 'V' |
53c1b30632df
updated for version 7.3.1265
Bram Moolenaar <bram@vim.org>
parents:
5010
diff
changeset
|
5184 || STRNCMP(skipwhite(e + 1), "set", 3) == 0) |
7 | 5185 && (s[3] == ':' |
5186 || (VIM_VERSION_100 >= vers && isdigit(s[3])) | |
5187 || (VIM_VERSION_100 < vers && s[3] == '<') | |
5188 || (VIM_VERSION_100 > vers && s[3] == '>') | |
5189 || (VIM_VERSION_100 == vers && s[3] == '='))) | |
5190 break; | |
5191 } | |
5192 } | |
5193 prev = *s; | |
5194 } | |
5195 | |
5196 if (*s) | |
5197 { | |
5198 do /* skip over "ex:", "vi:" or "vim:" */ | |
5199 ++s; | |
5200 while (s[-1] != ':'); | |
5201 | |
5202 s = linecopy = vim_strsave(s); /* copy the line, it will change */ | |
5203 if (linecopy == NULL) | |
5204 return FAIL; | |
5205 | |
5206 save_sourcing_lnum = sourcing_lnum; | |
5207 save_sourcing_name = sourcing_name; | |
5208 sourcing_lnum = lnum; /* prepare for emsg() */ | |
5209 sourcing_name = (char_u *)"modelines"; | |
5210 | |
5211 end = FALSE; | |
5212 while (end == FALSE) | |
5213 { | |
5214 s = skipwhite(s); | |
5215 if (*s == NUL) | |
5216 break; | |
5217 | |
5218 /* | |
5219 * Find end of set command: ':' or end of line. | |
5220 * Skip over "\:", replacing it with ":". | |
5221 */ | |
5222 for (e = s; *e != ':' && *e != NUL; ++e) | |
5223 if (e[0] == '\\' && e[1] == ':') | |
1618 | 5224 STRMOVE(e, e + 1); |
7 | 5225 if (*e == NUL) |
5226 end = TRUE; | |
5227 | |
5228 /* | |
5229 * If there is a "set" command, require a terminating ':' and | |
5230 * ignore the stuff after the ':'. | |
5231 * "vi:set opt opt opt: foo" -- foo not interpreted | |
5232 * "vi:opt opt opt: foo" -- foo interpreted | |
5233 * Accept "se" for compatibility with Elvis. | |
5234 */ | |
5235 if (STRNCMP(s, "set ", (size_t)4) == 0 | |
5236 || STRNCMP(s, "se ", (size_t)3) == 0) | |
5237 { | |
5238 if (*e != ':') /* no terminating ':'? */ | |
5239 break; | |
5240 end = TRUE; | |
5241 s = vim_strchr(s, ' ') + 1; | |
5242 } | |
5243 *e = NUL; /* truncate the set command */ | |
5244 | |
5245 if (*s != NUL) /* skip over an empty "::" */ | |
5246 { | |
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
|
5247 int secure_save = secure; |
7 | 5248 #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
|
5249 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
|
5250 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
|
5251 current_sctx.sc_seq = 0; |
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
|
5252 current_sctx.sc_lnum = 0; |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
5253 current_sctx.sc_version = 1; |
7 | 5254 #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
|
5255 // 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
|
5256 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
|
5257 |
717 | 5258 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
|
5259 |
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
|
5260 secure = secure_save; |
7 | 5261 #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
|
5262 current_sctx = save_current_sctx; |
7 | 5263 #endif |
5264 if (retval == FAIL) /* stop if error found */ | |
5265 break; | |
5266 } | |
5267 s = e + 1; /* advance to next part */ | |
5268 } | |
5269 | |
5270 sourcing_lnum = save_sourcing_lnum; | |
5271 sourcing_name = save_sourcing_name; | |
5272 | |
5273 vim_free(linecopy); | |
5274 } | |
5275 return retval; | |
5276 } | |
5277 | |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5278 /* |
14433
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5279 * 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
|
5280 */ |
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5281 int |
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5282 bt_normal(buf_T *buf) |
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5283 { |
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5284 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
|
5285 } |
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5286 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5287 #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
|
5288 /* |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5289 * 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
|
5290 */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5291 int |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5292 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
|
5293 { |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5294 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
|
5295 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5296 #endif |
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5297 |
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5298 #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
|
5299 /* |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5300 * 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
|
5301 */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5302 int |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5303 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
|
5304 { |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5305 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
|
5306 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5307 #endif |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5308 |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5309 /* |
11800
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5310 * 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
|
5311 */ |
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5312 int |
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5313 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
|
5314 { |
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5315 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
|
5316 } |
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5317 |
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5318 /* |
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
|
5319 * 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
|
5320 */ |
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
|
5321 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
|
5322 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
|
5323 { |
16778
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5324 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
|
5325 } |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5326 |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5327 /* |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5328 * 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
|
5329 */ |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5330 int |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5331 bt_popup(buf_T *buf) |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5332 { |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5333 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
|
5334 && 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
|
5335 } |
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
|
5336 |
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
|
5337 /* |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
5338 * 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
|
5339 * 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
|
5340 */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5341 int |
17095
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5342 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
|
5343 { |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5344 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
|
5345 || 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
|
5346 || 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
|
5347 || 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
|
5348 } |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5349 |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5350 /* |
17095
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5351 * 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
|
5352 */ |
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5353 int |
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5354 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
|
5355 { |
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5356 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
|
5357 } |
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5358 |
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5359 /* |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
5360 * 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
|
5361 * buffer. |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5362 */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5363 int |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5364 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
|
5365 { |
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
|
5366 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
|
5367 || 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
|
5368 || 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
|
5369 } |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5370 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5371 #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
|
5372 int |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5373 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
|
5374 { |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5375 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
|
5376 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5377 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
|
5378 return TRUE; |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5379 } |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5380 return FALSE; |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5381 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5382 #endif |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5383 |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5384 /* |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5385 * 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
|
5386 * and 'bufhidden'. |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5387 */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5388 int |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5389 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
|
5390 { |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5391 /* 'bufhidden' overrules 'hidden' and ":hide", check it first */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5392 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
|
5393 { |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5394 case 'u': /* "unload" */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5395 case 'w': /* "wipe" */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5396 case 'd': return FALSE; /* "delete" */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5397 case 'h': return TRUE; /* "hide" */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5398 } |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5399 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
|
5400 } |
7 | 5401 |
5402 /* | |
5403 * Return special buffer name. | |
5404 * Returns NULL when the buffer has a normal file name. | |
5405 */ | |
3839 | 5406 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5407 buf_spname(buf_T *buf) |
7 | 5408 { |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
5409 #if defined(FEAT_QUICKFIX) |
7 | 5410 if (bt_quickfix(buf)) |
643 | 5411 { |
5412 /* | |
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
|
5413 * 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
|
5414 * the buffer number stored in the global quickfix stack. |
643 | 5415 */ |
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
|
5416 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
|
5417 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
|
5418 else |
3839 | 5419 return (char_u *)_(msg_loclist); |
643 | 5420 } |
7 | 5421 #endif |
11772
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
5422 |
7 | 5423 /* There is no _file_ when 'buftype' is "nofile", b_sfname |
11772
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
5424 * 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
|
5425 if (bt_nofilename(buf)) |
7 | 5426 { |
11772
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
5427 #ifdef FEAT_TERMINAL |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
5428 if (buf->b_term != NULL) |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
5429 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
|
5430 #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
|
5431 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
|
5432 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
|
5433 #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
|
5434 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
|
5435 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
|
5436 #endif |
16859
0154363d3b98
patch 8.1.1431: popup window listed as "Scratch"
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5437 #ifdef FEAT_TEXT_PROP |
0154363d3b98
patch 8.1.1431: popup window listed as "Scratch"
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5438 if (bt_popup(buf)) |
0154363d3b98
patch 8.1.1431: popup window listed as "Scratch"
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5439 return (char_u *)_("[Popup]"); |
0154363d3b98
patch 8.1.1431: popup window listed as "Scratch"
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5440 #endif |
3839 | 5441 return (char_u *)_("[Scratch]"); |
7 | 5442 } |
11772
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
5443 |
7 | 5444 if (buf->b_fname == NULL) |
3839 | 5445 return (char_u *)_("[No Name]"); |
7 | 5446 return NULL; |
5447 } | |
5448 | |
5449 /* | |
5450 * Set 'buflisted' for curbuf to "on" and trigger autocommands if it changed. | |
5451 */ | |
5452 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5453 set_buflisted(int on) |
7 | 5454 { |
5455 if (on != curbuf->b_p_bl) | |
5456 { | |
5457 curbuf->b_p_bl = on; | |
5458 if (on) | |
5459 apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf); | |
5460 else | |
5461 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); | |
5462 } | |
5463 } | |
5464 | |
5465 /* | |
5466 * Read the file for "buf" again and check if the contents changed. | |
5467 * Return TRUE if it changed or this could not be checked. | |
5468 */ | |
5469 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5470 buf_contents_changed(buf_T *buf) |
7 | 5471 { |
5472 buf_T *newbuf; | |
5473 int differ = TRUE; | |
5474 linenr_T lnum; | |
5475 aco_save_T aco; | |
5476 exarg_T ea; | |
5477 | |
5478 /* Allocate a buffer without putting it in the buffer list. */ | |
5479 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); | |
5480 if (newbuf == NULL) | |
5481 return TRUE; | |
5482 | |
5483 /* Force the 'fileencoding' and 'fileformat' to be equal. */ | |
5484 if (prep_exarg(&ea, buf) == FAIL) | |
5485 { | |
5486 wipe_buffer(newbuf, FALSE); | |
5487 return TRUE; | |
5488 } | |
5489 | |
5490 /* set curwin/curbuf to buf and save a few things */ | |
5491 aucmd_prepbuf(&aco, newbuf); | |
5492 | |
625 | 5493 if (ml_open(curbuf) == OK |
7 | 5494 && readfile(buf->b_ffname, buf->b_fname, |
5495 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, | |
5496 &ea, READ_NEW | READ_DUMMY) == OK) | |
5497 { | |
5498 /* compare the two files line by line */ | |
5499 if (buf->b_ml.ml_line_count == curbuf->b_ml.ml_line_count) | |
5500 { | |
5501 differ = FALSE; | |
5502 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
5503 if (STRCMP(ml_get_buf(buf, lnum, FALSE), ml_get(lnum)) != 0) | |
5504 { | |
5505 differ = TRUE; | |
5506 break; | |
5507 } | |
5508 } | |
5509 } | |
5510 vim_free(ea.cmd); | |
5511 | |
5512 /* restore curwin/curbuf and a few other things */ | |
5513 aucmd_restbuf(&aco); | |
5514 | |
5515 if (curbuf != newbuf) /* safety check */ | |
5516 wipe_buffer(newbuf, FALSE); | |
5517 | |
5518 return differ; | |
5519 } | |
5520 | |
5521 /* | |
5522 * Wipe out a buffer and decrement the last buffer number if it was used for | |
5523 * this buffer. Call this to wipe out a temp buffer that does not contain any | |
5524 * marks. | |
5525 */ | |
5526 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5527 wipe_buffer( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5528 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5529 int aucmd UNUSED) /* When TRUE trigger autocommands. */ |
7 | 5530 { |
5531 if (buf->b_fnum == top_file_num - 1) | |
5532 --top_file_num; | |
5533 | |
5534 if (!aucmd) /* Don't trigger BufDelete autocommands here. */ | |
1410 | 5535 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
5536 |
3365 | 5537 close_buffer(NULL, buf, DOBUF_WIPE, FALSE); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
5538 |
7 | 5539 if (!aucmd) |
1410 | 5540 unblock_autocmds(); |
7 | 5541 } |