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