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