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