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