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