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