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