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