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