annotate src/evalbuffer.c @ 19728:41a1ea967a97 v8.2.0420

patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C Commit: https://github.com/vim/vim/commit/f1ec378b014efb9897422c40369a6462163a512a Author: Bram Moolenaar <Bram@vim.org> Date: Fri Mar 20 19:37:47 2020 +0100 patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C Problem: Vim9: cannot interrupt a loop with CTRL-C. Solution: Check for CTRL-C once in a while. Doesn't fully work yet.
author Bram Moolenaar <Bram@vim.org>
date Fri, 20 Mar 2020 19:45:03 +0100
parents 06f29b6ea04a
children 435726a03481
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18010
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * evalbuffer.c: Buffer related builtin functions
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #if defined(FEAT_EVAL) || defined(PROTO)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 * Mark references in functions of buffers.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 int
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 set_ref_in_buffers(int copyID)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 int abort = FALSE;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 buf_T *bp;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 FOR_ALL_BUFFERS(bp)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 listener_T *lnr;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 typval_T tv;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 for (lnr = bp->b_listener; !abort && lnr != NULL; lnr = lnr->lr_next)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 if (lnr->lr_callback.cb_partial != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 tv.v_type = VAR_PARTIAL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 tv.vval.v_partial = lnr->lr_callback.cb_partial;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 # ifdef FEAT_JOB_CHANNEL
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 if (!abort && bp->b_prompt_callback.cb_partial != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 tv.v_type = VAR_PARTIAL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 tv.vval.v_partial = bp->b_prompt_callback.cb_partial;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 if (!abort && bp->b_prompt_interrupt.cb_partial != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 tv.v_type = VAR_PARTIAL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 tv.vval.v_partial = bp->b_prompt_interrupt.cb_partial;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 # endif
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 if (abort)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 break;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 return abort;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 buf_T *
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 buflist_find_by_name(char_u *name, int curtab_only)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 int save_magic;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 char_u *save_cpo;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 buf_T *buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 // Ignore 'magic' and 'cpoptions' here to make scripts portable
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 save_magic = p_magic;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 p_magic = TRUE;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 save_cpo = p_cpo;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 p_cpo = (char_u *)"";
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 buf = buflist_findnr(buflist_findpat(name, name + STRLEN(name),
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 TRUE, FALSE, curtab_only));
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 p_magic = save_magic;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 p_cpo = save_cpo;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 return buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 * Find a buffer by number or exact name.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 buf_T *
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 find_buffer(typval_T *avar)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 buf_T *buf = NULL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 if (avar->v_type == VAR_NUMBER)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 buf = buflist_findnr((int)avar->vval.v_number);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 else if (avar->v_type == VAR_STRING && avar->vval.v_string != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 buf = buflist_findname_exp(avar->vval.v_string);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 if (buf == NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 // No full path name match, try a match with a URL or a "nofile"
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 // buffer, these don't use the full path.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 FOR_ALL_BUFFERS(buf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 if (buf->b_fname != NULL
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 && (path_with_url(buf->b_fname)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 #ifdef FEAT_QUICKFIX
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 || bt_nofilename(buf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 #endif
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 )
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 && STRCMP(buf->b_fname, avar->vval.v_string) == 0)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 break;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 return buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 * If there is a window for "curbuf", make it the current window.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 static void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 find_win_for_curbuf(void)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 wininfo_T *wip;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 for (wip = curbuf->b_wininfo; wip != NULL; wip = wip->wi_next)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 if (wip->wi_win != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 curwin = wip->wi_win;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 break;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 * Set line or list of lines in buffer "buf".
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 static void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 set_buffer_lines(
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 buf_T *buf,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 linenr_T lnum_arg,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 int append,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 typval_T *lines,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 linenr_T lnum = lnum_arg + (append ? 1 : 0);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 char_u *line = NULL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 list_T *l = NULL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 listitem_T *li = NULL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 long added = 0;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 linenr_T append_lnum;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 buf_T *curbuf_save = NULL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 win_T *curwin_save = NULL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 int is_curbuf = buf == curbuf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 // When using the current buffer ml_mfp will be set if needed. Useful when
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 // setline() is used on startup. For other buffers the buffer must be
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 // loaded.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 if (buf == NULL || (!is_curbuf && buf->b_ml.ml_mfp == NULL) || lnum < 1)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 rettv->vval.v_number = 1; // FAIL
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 return;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 if (!is_curbuf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 curbuf_save = curbuf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 curwin_save = curwin;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 curbuf = buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 find_win_for_curbuf();
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 if (append)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 // appendbufline() uses the line number below which we insert
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 append_lnum = lnum - 1;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 // setbufline() uses the line number above which we insert, we only
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 // append if it's below the last line
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 append_lnum = curbuf->b_ml.ml_line_count;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 if (lines->v_type == VAR_LIST)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 l = lines->vval.v_list;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18916
diff changeset
179 range_list_materialize(l);
18010
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 li = l->lv_first;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 line = tv_get_string_chk(lines);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 // default result is zero == OK
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 for (;;)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 if (l != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 // list argument, get next string
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 if (li == NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 break;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 line = tv_get_string_chk(&li->li_tv);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 li = li->li_next;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 rettv->vval.v_number = 1; // FAIL
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 if (line == NULL || lnum > curbuf->b_ml.ml_line_count + 1)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 break;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 // When coming here from Insert mode, sync undo, so that this can be
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 // undone separately from what was previously inserted.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 if (u_sync_once == 2)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 u_sync_once = 1; // notify that u_sync() was called
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 u_sync(TRUE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 if (!append && lnum <= curbuf->b_ml.ml_line_count)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 // Existing line, replace it.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 // Removes any existing text properties.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 if (u_savesub(lnum) == OK && ml_replace_len(
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 lnum, line, (colnr_T)STRLEN(line) + 1, TRUE, TRUE) == OK)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 changed_bytes(lnum, 0);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 if (is_curbuf && lnum == curwin->w_cursor.lnum)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 check_cursor_col();
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 rettv->vval.v_number = 0; // OK
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 else if (added > 0 || u_save(lnum - 1, lnum) == OK)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 // append the line
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 ++added;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 if (ml_append(lnum - 1, line, (colnr_T)0, FALSE) == OK)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 rettv->vval.v_number = 0; // OK
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 if (l == NULL) // only one string argument
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 break;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 ++lnum;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 if (added > 0)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 win_T *wp;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 tabpage_T *tp;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 appended_lines_mark(append_lnum, added);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 // Only adjust the cursor for buffers other than the current, unless it
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 // is the current window. For curbuf and other windows it has been
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 // done in mark_adjust_internal().
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 FOR_ALL_TAB_WINDOWS(tp, wp)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 if (wp->w_buffer == buf
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 && (wp->w_buffer != curbuf || wp == curwin)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 && wp->w_cursor.lnum > append_lnum)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 wp->w_cursor.lnum += added;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 check_cursor_col();
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 update_topline();
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 if (!is_curbuf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 curbuf = curbuf_save;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 curwin = curwin_save;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 * "append(lnum, string/list)" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 f_append(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 linenr_T lnum = tv_get_lnum(&argvars[0]);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 set_buffer_lines(curbuf, lnum, TRUE, &argvars[1], rettv);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 * "appendbufline(buf, lnum, string/list)" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 f_appendbufline(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 linenr_T lnum;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 buf_T *buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 buf = tv_get_buf(&argvars[0], FALSE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 if (buf == NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 rettv->vval.v_number = 1; // FAIL
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 lnum = tv_get_lnum_buf(&argvars[1], buf);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 set_buffer_lines(buf, lnum, TRUE, &argvars[2], rettv);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 * "bufadd(expr)" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 f_bufadd(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 char_u *name = tv_get_string(&argvars[0]);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 rettv->vval.v_number = buflist_add(*name == NUL ? NULL : name, 0);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 * "bufexists(expr)" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 f_bufexists(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 rettv->vval.v_number = (find_buffer(&argvars[0]) != NULL);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 * "buflisted(expr)" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 f_buflisted(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 buf_T *buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 buf = find_buffer(&argvars[0]);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 rettv->vval.v_number = (buf != NULL && buf->b_p_bl);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 * "bufload(expr)" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 f_bufload(typval_T *argvars, typval_T *rettv UNUSED)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 buf_T *buf = get_buf_arg(&argvars[0]);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 if (buf != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 buffer_ensure_loaded(buf);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 * "bufloaded(expr)" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 f_bufloaded(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 buf_T *buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 buf = find_buffer(&argvars[0]);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 rettv->vval.v_number = (buf != NULL && buf->b_ml.ml_mfp != NULL);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 * "bufname(expr)" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 f_bufname(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 buf_T *buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 if (argvars[0].v_type == VAR_UNKNOWN)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 buf = curbuf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 (void)tv_get_number(&argvars[0]); // issue errmsg if type error
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 ++emsg_off;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 buf = tv_get_buf(&argvars[0], FALSE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 --emsg_off;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 rettv->v_type = VAR_STRING;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 if (buf != NULL && buf->b_fname != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 rettv->vval.v_string = vim_strsave(buf->b_fname);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 rettv->vval.v_string = NULL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 * "bufnr(expr)" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 f_bufnr(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 buf_T *buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 int error = FALSE;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 char_u *name;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 if (argvars[0].v_type == VAR_UNKNOWN)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 buf = curbuf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 (void)tv_get_number(&argvars[0]); // issue errmsg if type error
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 ++emsg_off;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 buf = tv_get_buf(&argvars[0], FALSE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 --emsg_off;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 // If the buffer isn't found and the second argument is not zero create a
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 // new buffer.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 if (buf == NULL
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 && argvars[1].v_type != VAR_UNKNOWN
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 && tv_get_number_chk(&argvars[1], &error) != 0
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 && !error
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 && (name = tv_get_string_chk(&argvars[0])) != NULL
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 && !error)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 buf = buflist_new(name, NULL, (linenr_T)1, 0);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 if (buf != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 rettv->vval.v_number = buf->b_fnum;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 rettv->vval.v_number = -1;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 static void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 buf_win_common(typval_T *argvars, typval_T *rettv, int get_nr)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 win_T *wp;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 int winnr = 0;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 buf_T *buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 (void)tv_get_number(&argvars[0]); // issue errmsg if type error
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 ++emsg_off;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 buf = tv_get_buf(&argvars[0], TRUE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 FOR_ALL_WINDOWS(wp)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 ++winnr;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 if (wp->w_buffer == buf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 break;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 rettv->vval.v_number = (wp != NULL ? (get_nr ? winnr : wp->w_id) : -1);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 --emsg_off;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 * "bufwinid(nr)" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 f_bufwinid(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 buf_win_common(argvars, rettv, FALSE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 * "bufwinnr(nr)" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 f_bufwinnr(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 buf_win_common(argvars, rettv, TRUE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 * "deletebufline()" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 f_deletebufline(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 buf_T *buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 linenr_T first, last;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 linenr_T lnum;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 long count;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 int is_curbuf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 buf_T *curbuf_save = NULL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 win_T *curwin_save = NULL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 tabpage_T *tp;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 win_T *wp;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 buf = tv_get_buf(&argvars[0], FALSE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 if (buf == NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 rettv->vval.v_number = 1; // FAIL
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 return;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 is_curbuf = buf == curbuf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 first = tv_get_lnum_buf(&argvars[1], buf);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 if (argvars[2].v_type != VAR_UNKNOWN)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 last = tv_get_lnum_buf(&argvars[2], buf);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 last = first;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 if (buf->b_ml.ml_mfp == NULL || first < 1
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 || first > buf->b_ml.ml_line_count || last < first)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 rettv->vval.v_number = 1; // FAIL
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 return;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 if (!is_curbuf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 curbuf_save = curbuf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 curwin_save = curwin;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 curbuf = buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 find_win_for_curbuf();
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 if (last > curbuf->b_ml.ml_line_count)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 last = curbuf->b_ml.ml_line_count;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 count = last - first + 1;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 // When coming here from Insert mode, sync undo, so that this can be
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 // undone separately from what was previously inserted.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 if (u_sync_once == 2)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 u_sync_once = 1; // notify that u_sync() was called
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 u_sync(TRUE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 if (u_save(first - 1, last + 1) == FAIL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 rettv->vval.v_number = 1; // FAIL
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 return;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 for (lnum = first; lnum <= last; ++lnum)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 ml_delete(first, TRUE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 FOR_ALL_TAB_WINDOWS(tp, wp)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 if (wp->w_buffer == buf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 if (wp->w_cursor.lnum > last)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 wp->w_cursor.lnum -= count;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 else if (wp->w_cursor.lnum> first)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 wp->w_cursor.lnum = first;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 check_cursor_col();
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 deleted_lines_mark(first, count);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 if (!is_curbuf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 curbuf = curbuf_save;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 curwin = curwin_save;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 * Returns buffer options, variables and other attributes in a dictionary.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 static dict_T *
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 get_buffer_info(buf_T *buf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 dict_T *dict;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 tabpage_T *tp;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 win_T *wp;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 list_T *windows;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 dict = dict_alloc();
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 if (dict == NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 return NULL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 dict_add_number(dict, "bufnr", buf->b_fnum);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 dict_add_string(dict, "name", buf->b_ffname);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 dict_add_number(dict, "lnum", buf == curbuf ? curwin->w_cursor.lnum
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 : buflist_findlnum(buf));
18916
cf051bdefb3f patch 8.2.0019: cannot number of lines of another buffer
Bram Moolenaar <Bram@vim.org>
parents: 18777
diff changeset
549 dict_add_number(dict, "linecount", buf->b_ml.ml_line_count);
18010
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 dict_add_number(dict, "loaded", buf->b_ml.ml_mfp != NULL);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 dict_add_number(dict, "listed", buf->b_p_bl);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 dict_add_number(dict, "changed", bufIsChanged(buf));
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 dict_add_number(dict, "changedtick", CHANGEDTICK(buf));
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 dict_add_number(dict, "hidden",
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 buf->b_ml.ml_mfp != NULL && buf->b_nwindows == 0);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 // Get a reference to buffer variables
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 dict_add_dict(dict, "variables", buf->b_vars);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 // List of windows displaying this buffer
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 windows = list_alloc();
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 if (windows != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 FOR_ALL_TAB_WINDOWS(tp, wp)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 if (wp->w_buffer == buf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 list_append_number(windows, (varnumber_T)wp->w_id);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 dict_add_list(dict, "windows", windows);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18463
diff changeset
570 #ifdef FEAT_PROP_POPUP
18010
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 // List of popup windows displaying this buffer
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 windows = list_alloc();
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 if (windows != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 if (wp->w_buffer == buf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 list_append_number(windows, (varnumber_T)wp->w_id);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 FOR_ALL_TABPAGES(tp)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 if (wp->w_buffer == buf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 list_append_number(windows, (varnumber_T)wp->w_id);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 dict_add_list(dict, "popups", windows);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 #endif
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 #ifdef FEAT_SIGNS
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 if (buf->b_signlist != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 // List of signs placed in this buffer
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 list_T *signs = list_alloc();
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 if (signs != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 get_buffer_signs(buf, signs);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 dict_add_list(dict, "signs", signs);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 #endif
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599
18463
18d7337b6837 patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents: 18010
diff changeset
600 #ifdef FEAT_VIMINFO
18d7337b6837 patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents: 18010
diff changeset
601 dict_add_number(dict, "lastused", buf->b_last_used);
18d7337b6837 patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents: 18010
diff changeset
602 #endif
18d7337b6837 patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents: 18010
diff changeset
603
18010
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 return dict;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 * "getbufinfo()" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 f_getbufinfo(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 buf_T *buf = NULL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 buf_T *argbuf = NULL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 dict_T *d;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 int filtered = FALSE;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 int sel_buflisted = FALSE;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 int sel_bufloaded = FALSE;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 int sel_bufmodified = FALSE;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 if (rettv_list_alloc(rettv) != OK)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 return;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 // List of all the buffers or selected buffers
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 if (argvars[0].v_type == VAR_DICT)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 dict_T *sel_d = argvars[0].vval.v_dict;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 if (sel_d != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 dictitem_T *di;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 filtered = TRUE;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 di = dict_find(sel_d, (char_u *)"buflisted", -1);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 if (di != NULL && tv_get_number(&di->di_tv))
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 sel_buflisted = TRUE;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 di = dict_find(sel_d, (char_u *)"bufloaded", -1);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 if (di != NULL && tv_get_number(&di->di_tv))
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 sel_bufloaded = TRUE;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 di = dict_find(sel_d, (char_u *)"bufmodified", -1);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 if (di != NULL && tv_get_number(&di->di_tv))
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 sel_bufmodified = TRUE;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 else if (argvars[0].v_type != VAR_UNKNOWN)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 // Information about one buffer. Argument specifies the buffer
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 (void)tv_get_number(&argvars[0]); // issue errmsg if type error
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 ++emsg_off;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 argbuf = tv_get_buf(&argvars[0], FALSE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 --emsg_off;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 if (argbuf == NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 return;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 // Return information about all the buffers or a specified buffer
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 FOR_ALL_BUFFERS(buf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 if (argbuf != NULL && argbuf != buf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 continue;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 if (filtered && ((sel_bufloaded && buf->b_ml.ml_mfp == NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 || (sel_buflisted && !buf->b_p_bl)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 || (sel_bufmodified && !buf->b_changed)))
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 continue;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 d = get_buffer_info(buf);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 if (d != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 list_append_dict(rettv->vval.v_list, d);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 if (argbuf != NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 return;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 * Get line or list of lines from buffer "buf" into "rettv".
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 * Return a range (from start to end) of lines in rettv from the specified
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 * buffer.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 * If 'retlist' is TRUE, then the lines are returned as a Vim List.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 static void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 get_buffer_lines(
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 buf_T *buf,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 linenr_T start,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 linenr_T end,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 int retlist,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 char_u *p;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18916
diff changeset
693 if (retlist)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18916
diff changeset
694 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18916
diff changeset
695 if (rettv_list_alloc(rettv) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18916
diff changeset
696 return;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18916
diff changeset
697 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18916
diff changeset
698 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18916
diff changeset
699 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18916
diff changeset
700 rettv->v_type = VAR_STRING;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18916
diff changeset
701 rettv->vval.v_string = NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18916
diff changeset
702 }
18010
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 if (buf == NULL || buf->b_ml.ml_mfp == NULL || start < 0)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 return;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 if (!retlist)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 if (start >= 1 && start <= buf->b_ml.ml_line_count)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 p = ml_get_buf(buf, start, FALSE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 p = (char_u *)"";
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 rettv->vval.v_string = vim_strsave(p);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 if (end < start)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 return;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 if (start < 1)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 start = 1;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 if (end > buf->b_ml.ml_line_count)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 end = buf->b_ml.ml_line_count;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 while (start <= end)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 if (list_append_string(rettv->vval.v_list,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 ml_get_buf(buf, start++, FALSE), -1) == FAIL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 break;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 * "getbufline()" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 f_getbufline(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 linenr_T lnum;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 linenr_T end;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 buf_T *buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 (void)tv_get_number(&argvars[0]); // issue errmsg if type error
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 ++emsg_off;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 buf = tv_get_buf(&argvars[0], FALSE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 --emsg_off;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 lnum = tv_get_lnum_buf(&argvars[1], buf);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 if (argvars[2].v_type == VAR_UNKNOWN)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 end = lnum;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 end = tv_get_lnum_buf(&argvars[2], buf);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 get_buffer_lines(buf, lnum, end, TRUE, rettv);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754
19564
06f29b6ea04a patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
755 type_T *
06f29b6ea04a patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
756 ret_f_getline(int argcount, type_T **argtypes UNUSED)
06f29b6ea04a patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
757 {
06f29b6ea04a patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
758 return argcount == 1 ? &t_string : &t_list_string;
06f29b6ea04a patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
759 }
06f29b6ea04a patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
760
18010
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 * "getline(lnum, [end])" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 f_getline(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 linenr_T lnum;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 linenr_T end;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 int retlist;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 lnum = tv_get_lnum(argvars);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 if (argvars[1].v_type == VAR_UNKNOWN)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 end = 0;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 retlist = FALSE;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 end = tv_get_lnum(&argvars[1]);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 retlist = TRUE;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 get_buffer_lines(curbuf, lnum, end, retlist, rettv);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 * "setbufline()" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 f_setbufline(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 linenr_T lnum;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 buf_T *buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 buf = tv_get_buf(&argvars[0], FALSE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 if (buf == NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 rettv->vval.v_number = 1; // FAIL
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 lnum = tv_get_lnum_buf(&argvars[1], buf);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 set_buffer_lines(buf, lnum, FALSE, &argvars[2], rettv);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 * "setline()" function
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 f_setline(typval_T *argvars, typval_T *rettv)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 linenr_T lnum = tv_get_lnum(&argvars[0]);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 set_buffer_lines(curbuf, lnum, FALSE, &argvars[1], rettv);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 #endif // FEAT_EVAL
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 #if defined(FEAT_JOB_CHANNEL) \
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 || defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) \
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 || defined(PROTO)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 * Make "buf" the current buffer. restore_buffer() MUST be called to undo.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 * No autocommands will be executed. Use aucmd_prepbuf() if there are any.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 switch_buffer(bufref_T *save_curbuf, buf_T *buf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 block_autocmds();
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 set_bufref(save_curbuf, curbuf);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 --curbuf->b_nwindows;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 curbuf = buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 curwin->w_buffer = buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 ++curbuf->b_nwindows;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 * Restore the current buffer after using switch_buffer().
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 restore_buffer(bufref_T *save_curbuf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 unblock_autocmds();
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
842 // Check for valid buffer, just in case.
18010
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 if (bufref_valid(save_curbuf))
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 --curbuf->b_nwindows;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 curwin->w_buffer = save_curbuf->br_buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 curbuf = save_curbuf->br_buf;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 ++curbuf->b_nwindows;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 * Find a window for buffer "buf".
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 * If found OK is returned and "wp" and "tp" are set to the window and tabpage.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 * If not found FAIL is returned.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 static int
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 find_win_for_buf(
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 buf_T *buf,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 win_T **wp,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 tabpage_T **tp)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 FOR_ALL_TAB_WINDOWS(*tp, *wp)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 if ((*wp)->w_buffer == buf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 return OK;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 return FAIL;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 /*
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 * Find a window that contains "buf" and switch to it.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 * If there is no such window, use the current window and change "curbuf".
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 * Caller must initialize save_curbuf to NULL.
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 * restore_win_for_buf() MUST be called later!
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 */
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 switch_to_win_for_buf(
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 buf_T *buf,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 win_T **save_curwinp,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 tabpage_T **save_curtabp,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 bufref_T *save_curbuf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 win_T *wp;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 tabpage_T *tp;
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 if (find_win_for_buf(buf, &wp, &tp) == FAIL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 switch_buffer(save_curbuf, buf);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 else if (switch_win(save_curwinp, save_curtabp, wp, tp, TRUE) == FAIL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 restore_win(*save_curwinp, *save_curtabp, TRUE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 switch_buffer(save_curbuf, buf);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 void
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 restore_win_for_buf(
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 win_T *save_curwin,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 tabpage_T *save_curtab,
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 bufref_T *save_curbuf)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 {
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 if (save_curbuf->br_buf == NULL)
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 restore_win(save_curwin, save_curtab, TRUE);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 else
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 restore_buffer(save_curbuf);
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 }
cf8e0c7e0cb9 patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 #endif