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