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