annotate src/if_tcl.c @ 25376:485ae4421331 v8.2.3225

patch 8.2.3225: incsearch highlighting is attempted halfway a mapping Commit: https://github.com/vim/vim/commit/ccb148ac63941feba879ea4678aa4713d81494f2 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 26 21:11:32 2021 +0200 patch 8.2.3225: incsearch highlighting is attempted halfway a mapping Problem: Incsearch highlighting is attempted halfway a mapping. Solution: Only do incsearch highlighting if keys were typed or there is no more typeahead.
author Bram Moolenaar <Bram@vim.org>
date Mon, 26 Jul 2021 21:15:08 +0200
parents c4298ed56ffa
children 9a1b96ae26d1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * Tcl extensions by Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 * Last modification: Wed May 10 21:28:44 CEST 2000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 * Requires Tcl 8.0 or higher.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 * Variables:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 * ::vim::current(buffer) # Name of buffer command for current buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 * ::vim::current(window) # Name of window command for current window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 * ::vim::range(start) # Start of current range (line number).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 * ::vim::range(end) # End of current range (line number).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 * ::vim::lbase # Start of line/column numbers (1 or 0).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 * Commands:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 * ::vim::command {cmd} # Execute ex command {cmd}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 * ::vim::option {opt} [val] # Get/Set option {opt}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 * ::vim::expr {expr} # Evaluate {expr} using vim's evaluator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 * ::vim::beep # Guess.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 * set buf [::vim::buffer {n}] # Create Tcl command for buffer N.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 * set bl [::vim::buffer list] # Get list of Tcl commands of all buffers.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 * ::vim::buffer exists {n} # True if buffer {n} exists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 * set wl [::vim::window list] # Get list of Tcl commands of all windows.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 * set n [$win height] # Report window height.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 * $win height {n} # Set window height to {n}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 * array set pos [$win cursor] # Get cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 * $win cursor {row} {col} # Set cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 * $win cursor pos # Set cursor position from array var "pos"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 * $win delcmd {cmd} # Register callback command for closed window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 * $win option {opt} [val] # Get/Set vim option in context of $win.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 * $win command {cmd} # Execute ex command in context of $win.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 * $win expr {expr} # Evaluate vim expression in context of $win.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 * set buf [$win buffer] # Create Tcl command for window's buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 * $buf name # Reports file name in buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 * $buf number # Reports buffer number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 * set l [$buf get {n}] # Get buffer line {n} as a string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 * set L [$buf get {n} {m}] # Get lines {n} through {m} as a list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 * $buf count # Reports number of lines in buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 * $buf last # Reports number of last line in buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 * $buf delete {n} # Delete line {n}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 * $buf delete {n} {m} # Delete lines {n} through {m}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 * $buf set {n} {l} # Set line {n} to string {l}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 * $buf set {n} {m} {L} # Set lines {n} through {m} from list {L}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 * # Delete/inserts lines as appropriate.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 * $buf option {opt} [val] # Get/Set vim option in context of $buf.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 * $buf command {cmd} # Execute ex command in context of $buf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 * $buf expr {cmd} # Evaluate vim expression in context of $buf.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 * array set pos [$buf mark {m}] # Get position of mark.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 * $buf append {n} {str} # Append string {str} to buffer,after line {n}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 * $buf insert {n} {str} # Insert string {str} in buffer as line {n}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 * $buf delcmd {cmd} # Register callback command for deleted buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 * set wl [$buf windows] # Get list of Tcl commands for all windows of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 * # this buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 TODO:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 * ::vim::buffer new # create new buffer + Tcl command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 #include "vim.h"
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
70 #undef EXTERN // tcl.h defines it too
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 #ifdef DYNAMIC_TCL
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
73 # define USE_TCL_STUBS // use tcl's stubs mechanism
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 #include <tcl.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 #include <string.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 typedef struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 Tcl_Interp *interp;
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
82 int exitvalue;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 int range_start, range_end;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 int lbase;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 char *curbuf, *curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 } tcl_info;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
88 static tcl_info tclinfo = { NULL, 0, 0, 0, 0, NULL, NULL };
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 #define VAR_RANGE1 "::vim::range(start)"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 #define VAR_RANGE2 "::vim::range(begin)"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 #define VAR_RANGE3 "::vim::range(end)"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 #define VAR_CURBUF "::vim::current(buffer)"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 #define VAR_CURWIN "::vim::current(window)"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 #define VAR_LBASE "::vim::lbase"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 #define VAR_CURLINE "line"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 #define VAR_CURLNUM "lnum"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 #define VARNAME_SIZE 64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 #define row2tcl(x) ((x) - (tclinfo.lbase==0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 #define row2vim(x) ((x) + (tclinfo.lbase==0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 #define col2tcl(x) ((x) + (tclinfo.lbase!=0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 #define col2vim(x) ((x) - (tclinfo.lbase!=0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 #define VIMOUT ((ClientData)1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 #define VIMERR ((ClientData)2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
109 // This appears to be new in Tcl 8.4.
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 7
diff changeset
110 #ifndef CONST84
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 7
diff changeset
111 # define CONST84
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 7
diff changeset
112 #endif
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 7
diff changeset
113
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 * List of Tcl interpreters who reference a vim window or buffer.
15034
6e4e0d43b20b patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 14395
diff changeset
116 * Each buffer and window has its own list in the w_tcl_ref or b_tcl_ref
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 274
diff changeset
117 * struct member. We need this because Tcl can create sub-interpreters with
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 274
diff changeset
118 * the "interp" command, and each interpreter can reference all windows and
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 274
diff changeset
119 * buffers.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 struct ref
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 struct ref *next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 Tcl_Interp *interp;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
126 Tcl_Command cmd; // Tcl command that represents this object
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
127 Tcl_Obj *delcmd; // Tcl command to call when object is being del.
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
128 void *vimobj; // Vim window or buffer (win_T* or buf_T*)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 static char * tclgetbuffer _ANSI_ARGS_((Tcl_Interp *interp, buf_T *buf));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 static char * tclgetwindow _ANSI_ARGS_((Tcl_Interp *interp, win_T *win));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 static int tclsetdelcmd _ANSI_ARGS_((Tcl_Interp *interp, struct ref *reflist, void *vimobj, Tcl_Obj *delcmd));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 static int tclgetlinenum _ANSI_ARGS_ ((Tcl_Interp *interp, Tcl_Obj *obj, int *valueP, buf_T *buf));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 static win_T *tclfindwin _ANSI_ARGS_ ((buf_T *buf));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 static int tcldoexcommand _ANSI_ARGS_ ((Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], int objn));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 static int tclsetoption _ANSI_ARGS_ ((Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], int objn));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 static int tclvimexpr _ANSI_ARGS_ ((Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], int objn));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 static void tcldelthisinterp _ANSI_ARGS_ ((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 static int vimerror _ANSI_ARGS_((Tcl_Interp *interp));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 static void tclmsg _ANSI_ARGS_((char *text));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 static void tclerrmsg _ANSI_ARGS_((char *text));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 static void tclupdatevars _ANSI_ARGS_((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
145 static struct ref refsdeleted; // dummy object for deleted ref list
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
147 //////////////////////////////////////////////////////////////////////////////
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
148 // TCL interface manager
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
149 ////////////////////////////////////////////////////////////////////////////
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 #if defined(DYNAMIC_TCL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 # ifndef DYNAMIC_TCL_DLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 # define DYNAMIC_TCL_DLL "tcl83.dll"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 # ifndef DYNAMIC_TCL_VER
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 # define DYNAMIC_TCL_VER "8.3"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
159 # ifndef DYNAMIC_TCL // Just generating prototypes
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 typedef int HANDLE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
163 # ifndef MSWIN
7538
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
164 # include <dlfcn.h>
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
165 # define HANDLE void*
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
166 # define TCL_PROC void*
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
167 # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
168 # define symbol_from_dll dlsym
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
169 # define close_dll dlclose
25342
c4298ed56ffa patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents: 24930
diff changeset
170 # define load_dll_error dlerror
7538
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
171 # else
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
172 # define TCL_PROC FARPROC
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
173 # define load_dll vimLoadLib
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
174 # define symbol_from_dll GetProcAddress
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
175 # define close_dll FreeLibrary
25342
c4298ed56ffa patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents: 24930
diff changeset
176 # define load_dll_error GetWin32Error
7538
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
177 # endif
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
178
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 /*
1890
2928a6b338c3 updated for version 7.2-187
vimboss
parents: 1889
diff changeset
180 * Declare HANDLE for tcl.dll and function pointers.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 static HANDLE hTclLib = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 Tcl_Interp* (*dll_Tcl_CreateInterp)();
5390
68056d414f09 updated for version 7.4.046
Bram Moolenaar <bram@vim.org>
parents: 5267
diff changeset
184 void (*dll_Tcl_FindExecutable)(const void *);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 * Table of name to function pointer of tcl.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 static struct {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 char* name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 TCL_PROC* ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 } tcl_funcname_table[] = {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 {"Tcl_CreateInterp", (TCL_PROC*)&dll_Tcl_CreateInterp},
5390
68056d414f09 updated for version 7.4.046
Bram Moolenaar <bram@vim.org>
parents: 5267
diff changeset
194 {"Tcl_FindExecutable", (TCL_PROC*)&dll_Tcl_FindExecutable},
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 {NULL, NULL},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 * Make all runtime-links of tcl.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 * 1. Get module handle using LoadLibraryEx.
1890
2928a6b338c3 updated for version 7.2-187
vimboss
parents: 1889
diff changeset
202 * 2. Get pointer to tcl function by GetProcAddress.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 * 3. Repeat 2, until get all functions will be used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 * Parameter 'libname' provides name of DLL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 tcl_runtime_link_init(char *libname, int verbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 if (hTclLib)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 return OK;
7538
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
215 if (!(hTclLib = load_dll(libname)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 if (verbose)
25342
c4298ed56ffa patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents: 24930
diff changeset
218 semsg(_(e_loadlib), libname, load_dll_error());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 for (i = 0; tcl_funcname_table[i].ptr; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 {
7538
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
223 if (!(*tcl_funcname_table[i].ptr = symbol_from_dll(hTclLib,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 tcl_funcname_table[i].name)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 {
7538
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
226 close_dll(hTclLib);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 hTclLib = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15034
diff changeset
229 semsg(_(e_loadfunc), tcl_funcname_table[i].name);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
235 #endif // defined(DYNAMIC_TCL) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 #ifdef DYNAMIC_TCL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 static char *find_executable_arg = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
242 vim_tcl_init(char *arg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 #ifndef DYNAMIC_TCL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 Tcl_FindExecutable(arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 find_executable_arg = arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 #if defined(DYNAMIC_TCL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 static int stubs_initialized = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 * Return TRUE if the TCL interface can be used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
259 tcl_enabled(int verbose)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 if (!stubs_initialized && find_executable_arg != NULL
7538
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
262 && tcl_runtime_link_init((char *)p_tcldll, verbose) == OK)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 Tcl_Interp *interp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265
5390
68056d414f09 updated for version 7.4.046
Bram Moolenaar <bram@vim.org>
parents: 5267
diff changeset
266 dll_Tcl_FindExecutable(find_executable_arg);
68056d414f09 updated for version 7.4.046
Bram Moolenaar <bram@vim.org>
parents: 5267
diff changeset
267
7538
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
268 if ((interp = dll_Tcl_CreateInterp()) != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 if (Tcl_InitStubs(interp, DYNAMIC_TCL_VER, 0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 Tcl_DeleteInterp(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 stubs_initialized = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
275 // FIXME: When Tcl_InitStubs() was failed, how delete interp?
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 return stubs_initialized;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
283 tcl_end(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
287 /////////////////////////////////////////////////////////////////////////////
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
288 // Tcl commands
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
289 ////////////////////////////////////////////////////////////////////////////
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 /*
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
292 * Replace standard "exit" command.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 *
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
294 * Delete the Tcl interpreter; a new one will be created with the next
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
295 * :tcl command). The exit code is saved (and retrieved in tclexit()).
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
296 * Since Tcl's exit is never expected to return and this replacement
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
297 * does, then (except for a trivial case) additional Tcl commands will
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
298 * be run. Since the interpreter is now marked as deleted, an error
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
299 * will be returned -- typically "attempt to call eval in deleted
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
300 * interpreter". Hopefully, at this point, checks for TCL_ERROR take
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
301 * place and control percolates back up to Vim -- but with this new error
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
302 * string in the interpreter's result value. Therefore it would be
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
303 * useless for this routine to return the exit code via Tcl_SetResult().
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
306 exitcmd(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
307 ClientData dummy UNUSED,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
308 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
309 int objc,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
310 Tcl_Obj *CONST objv[])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 int value = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 switch (objc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 case 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 if (Tcl_GetIntFromObj(interp, objv[1], &value) != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 break;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
319 // FALLTHROUGH
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 case 1:
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
321 tclinfo.exitvalue = value;
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
322
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
323 Tcl_DeleteInterp(interp);
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
324 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 Tcl_WrongNumArgs(interp, 1, objv, "?returnCode?");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 * "::vim::beep" - what Vi[m] does best :-)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
335 beepcmd(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
336 ClientData dummy UNUSED,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
337 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
338 int objc,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
339 Tcl_Obj *CONST objv[])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 if (objc != 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 Tcl_WrongNumArgs(interp, 1, objv, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 }
6949
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 5390
diff changeset
346 vim_beep(BO_LANG);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 return TCL_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 * "::vim::buffer list" - create a list of buffer commands.
1222
756bed568f5d updated for version 7.1b
vimboss
parents: 1125
diff changeset
352 * "::vim::buffer {N}" - create buffer command for buffer N.
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
353 * "::vim::buffer exists {N}" - test if buffer N exists.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 * "::vim::buffer new" - create a new buffer (not implemented)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
357 buffercmd(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
358 ClientData dummy UNUSED,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
359 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
360 int objc,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
361 Tcl_Obj *CONST objv[])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 char *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 Tcl_Obj *resobj;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 int err, n, idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 enum {BCMD_EXISTS, BCMD_LIST};
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 7
diff changeset
368 static CONST84 char *bcmdoptions[] =
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 "exists", "list", (char *)0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 if (objc < 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 Tcl_WrongNumArgs(interp, 1, objv, "option");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 err = Tcl_GetIntFromObj(interp, objv[1], &n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 if (err == TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 if (objc != 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 Tcl_WrongNumArgs(interp, 1, objv, "bufNumber");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 }
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 7823
diff changeset
386 FOR_ALL_BUFFERS(buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 if (buf->b_fnum == n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 name = tclgetbuffer(interp, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 if (name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 Tcl_SetResult(interp, name, TCL_VOLATILE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 return TCL_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 Tcl_SetResult(interp, _("invalid buffer number"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
400 Tcl_ResetResult(interp); // clear error from Tcl_GetIntFromObj
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 err = Tcl_GetIndexFromObj(interp, objv[1], bcmdoptions, "option", 0, &idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 return err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 switch (idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 case BCMD_LIST:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 if (objc != 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 Tcl_WrongNumArgs(interp, 2, objv, "");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 }
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 7823
diff changeset
414 FOR_ALL_BUFFERS(buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 name = tclgetbuffer(interp, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 if (name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 Tcl_AppendElement(interp, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 case BCMD_EXISTS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 if (objc != 3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 Tcl_WrongNumArgs(interp, 2, objv, "bufNumber");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 err = Tcl_GetIntFromObj(interp, objv[2], &n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 if (err == TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 buf = buflist_findnr(n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 resobj = Tcl_NewIntObj(buf != NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 Tcl_SetObjResult(interp, resobj);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 Tcl_SetResult(interp, _("not implemented yet"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 return err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 * "::vim::window list" - create list of window commands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
453 windowcmd(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
454 ClientData dummy UNUSED,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
455 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
456 int objc,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
457 Tcl_Obj *CONST objv[])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 char *what, *string;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 win_T *win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 if (objc != 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 Tcl_WrongNumArgs(interp, 1, objv, "option");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 what = Tcl_GetStringFromObj(objv[1], NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 if (strcmp(what, "list") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 FOR_ALL_WINDOWS(win)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 string = tclgetwindow(interp, win);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 if (string == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 Tcl_AppendElement(interp, string);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 return TCL_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 Tcl_SetResult(interp, _("unknown option"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 * flags for bufselfcmd and winselfcmd to indicate outstanding actions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 #define FL_UPDATE_SCREEN (1<<0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 #define FL_UPDATE_CURBUF (1<<1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 #define FL_ADJUST_CURSOR (1<<2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 * This function implements the buffer commands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
494 bufselfcmd(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
495 ClientData ref,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
496 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
497 int objc,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
498 Tcl_Obj *CONST objv[])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 int opt, err, idx, flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 int val1, val2, n, i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 buf_T *buf, *savebuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 win_T *win, *savewin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 Tcl_Obj *resobj;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 pos_T *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 char *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 enum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 BUF_APPEND, BUF_COMMAND, BUF_COUNT, BUF_DELCMD, BUF_DELETE, BUF_EXPR,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 BUF_GET, BUF_INSERT, BUF_LAST, BUF_MARK, BUF_NAME, BUF_NUMBER,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 BUF_OPTION, BUF_SET, BUF_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 };
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 7
diff changeset
514 static CONST84 char *bufoptions[] =
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 "append", "command", "count", "delcmd", "delete", "expr",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 "get", "insert", "last", "mark", "name", "number",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 "option", "set", "windows", (char *)0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 if (objc < 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 err = Tcl_GetIndexFromObj(interp, objv[1], bufoptions, "option", 0, &idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 return err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 buf = (buf_T *)((struct ref *)ref)->vimobj;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 savebuf = curbuf; curbuf = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 savewin = curwin; curwin = tclfindwin(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 flags = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 opt = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 switch (idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 case BUF_COMMAND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 err = tcldoexcommand(interp, objc, objv, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 flags |= FL_UPDATE_SCREEN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 case BUF_OPTION:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 err = tclsetoption(interp, objc, objv, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 flags |= FL_UPDATE_SCREEN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 case BUF_EXPR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 err = tclvimexpr(interp, objc, objv, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 case BUF_NAME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 * Get filename of buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 if (objc != 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 Tcl_WrongNumArgs(interp, 2, objv, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 if (buf->b_ffname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 Tcl_SetResult(interp, (char *)buf->b_ffname, TCL_VOLATILE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 Tcl_SetResult(interp, "", TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 case BUF_LAST:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 * Get line number of last line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 opt = 1;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
574 // fallthrough
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 case BUF_COUNT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 * Get number of lines in buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 if (objc != 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 Tcl_WrongNumArgs(interp, 2, objv, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 val1 = (int)buf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 if (opt)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 val1 = row2tcl(val1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 resobj = Tcl_NewIntObj(val1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 Tcl_SetObjResult(interp, resobj);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 case BUF_NUMBER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 * Get buffer's number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 if (objc != 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 Tcl_WrongNumArgs(interp, 2, objv, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 resobj = Tcl_NewIntObj((int)buf->b_fnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 Tcl_SetObjResult(interp, resobj);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 case BUF_GET:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 if (objc != 3 && objc != 4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 Tcl_WrongNumArgs(interp, 2, objv, "lineNumber ?lineNumber?");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 err = tclgetlinenum(interp, objv[2], &val1, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 if (objc == 4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 err = tclgetlinenum(interp, objv[3], &val2, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 if (val1 > val2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 n = val1; val1 = val2; val2 = n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 Tcl_ResetResult(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 for (n = val1; n <= val2 && err == TCL_OK; n++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 line = (char *)ml_get_buf(buf, (linenr_T)n, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 if (line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 Tcl_AppendElement(interp, line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
637 else { // objc == 3
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 line = (char *)ml_get_buf(buf, (linenr_T)val1, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 Tcl_SetResult(interp, line, TCL_VOLATILE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 case BUF_SET:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 if (objc != 4 && objc != 5)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 Tcl_WrongNumArgs(interp, 3, objv, "lineNumber ?lineNumber? stringOrList");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 err = tclgetlinenum(interp, objv[2], &val1, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 if (objc == 4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 * Replace one line with a string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 * $buf set {n} {string}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 line = Tcl_GetStringFromObj(objv[3], NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 if (u_savesub((linenr_T)val1) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 Tcl_SetResult(interp, _("cannot save undo information"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 if (ml_replace((linenr_T)val1, (char_u *)line, TRUE) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 Tcl_SetResult(interp, _("cannot replace line"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 changed_bytes((linenr_T)val1, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 flags |= FL_UPDATE_CURBUF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 * Replace several lines with the elements of a Tcl list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 * $buf set {n} {m} {list}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 * If the list contains more than {m}-{n}+1 elements, they
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 * are * inserted after line {m}. If the list contains fewer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 * elements, * the lines from {n}+length({list}) through {m}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 * are deleted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 int lc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 Tcl_Obj **lv;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 err = tclgetlinenum(interp, objv[3], &val2, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 err = Tcl_ListObjGetElements(interp, objv[4], &lc, &lv);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 if (val1 > val2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 n = val1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 val1 = val2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 val2 = n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 n = val1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 if (u_save((linenr_T)(val1 - 1), (linenr_T)(val2 + 1)) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 Tcl_SetResult(interp, _("cannot save undo information"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 flags |= FL_UPDATE_CURBUF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 for (i = 0; i < lc && n <= val2; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 line = Tcl_GetStringFromObj(lv[i], NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 if (ml_replace((linenr_T)n, (char_u *)line, TRUE) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 goto setListError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 ++n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 if (i < lc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
723 // append lines
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 line = Tcl_GetStringFromObj(lv[i], NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 if (ml_append((linenr_T)(n - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 (char_u *)line, 0, FALSE) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 goto setListError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 ++n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 } while (i < lc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 else if (n <= val2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
736 // did not replace all lines, delete
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 i = n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 {
20599
d571231175b4 patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents: 20369
diff changeset
740 if (ml_delete((linenr_T)i) != OK)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 goto setListError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 ++n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 } while (n <= val2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
745 lc -= val2 - val1 + 1; // number of lines to be replaced
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 mark_adjust((linenr_T)val1, (linenr_T)val2, (long)MAXLNUM,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 (long)lc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 changed_lines((linenr_T)val1, 0, (linenr_T)val2 + 1, (long)lc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 setListError:
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
751 u_undo(1); // ???
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 Tcl_SetResult(interp, _("cannot set line(s)"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 case BUF_DELETE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 if (objc != 3 && objc != 4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 Tcl_WrongNumArgs(interp, 3, objv, "lineNumber ?lineNumber?");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 err = tclgetlinenum(interp, objv[2], &val1, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 val2 = val1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 if (objc == 4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 err = tclgetlinenum(interp, objv[3], &val2, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 return err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 if (val1 > val2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 i = val1; val1 = val2; val2 = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 n = val2 - val1 + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 if (u_savedel((linenr_T)val1, (long)n) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 Tcl_SetResult(interp, _("cannot save undo information"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 for (i = 0; i < n; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 {
20599
d571231175b4 patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents: 20369
diff changeset
788 ml_delete((linenr_T)val1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 err = vimerror(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 if (i > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 deleted_lines_mark((linenr_T)val1, (long)i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 flags |= FL_ADJUST_CURSOR|FL_UPDATE_SCREEN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 case BUF_MARK:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 if (objc != 3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 Tcl_WrongNumArgs(interp, 2, objv, "markName");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 line = Tcl_GetStringFromObj(objv[2], NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 pos = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 if (line[0] != '\0' && line[1] == '\0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 pos = getmark(line[0], FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 if (pos == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 Tcl_SetResult(interp, _("invalid mark name"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 err = vimerror(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 if (pos->lnum <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 Tcl_SetResult(interp, _("mark not set"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 char rbuf[64];
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 135
diff changeset
827
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 135
diff changeset
828 sprintf(rbuf, _("row %d column %d"),
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 135
diff changeset
829 (int)row2tcl(pos->lnum), (int)col2tcl(pos->col));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 Tcl_SetResult(interp, rbuf, TCL_VOLATILE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 case BUF_INSERT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 opt = 1;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
836 // fallthrough
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 case BUF_APPEND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 if (objc != 4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 Tcl_WrongNumArgs(interp, 2, objv, "lineNum text");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 err = tclgetlinenum(interp, objv[2], &val1, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 if (opt)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 --val1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 if (u_save((linenr_T)val1, (linenr_T)(val1+1)) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 {
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 135
diff changeset
851 Tcl_SetResult(interp, _("cannot save undo information"),
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 135
diff changeset
852 TCL_STATIC);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 line = Tcl_GetStringFromObj(objv[3], NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 if (ml_append((linenr_T)val1, (char_u *)line, 0, FALSE) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 {
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 135
diff changeset
860 Tcl_SetResult(interp, _("cannot insert/append line"),
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 135
diff changeset
861 TCL_STATIC);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 appended_lines_mark((linenr_T)val1, 1L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 flags |= FL_UPDATE_SCREEN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 case BUF_WINDOWS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 * Return list of window commands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 if (objc != 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 Tcl_WrongNumArgs(interp, 2, objv, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 Tcl_ResetResult(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 FOR_ALL_WINDOWS(win)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 if (win->w_buffer == buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 line = tclgetwindow(interp, win);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 if (line != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 Tcl_AppendElement(interp, line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 case BUF_DELCMD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 * Register deletion callback.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 * TODO: Should be able to register multiple callbacks
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 if (objc != 3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 Tcl_WrongNumArgs(interp, 2, objv, "command");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 }
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 274
diff changeset
907 err = tclsetdelcmd(interp, buf->b_tcl_ref, (void *)buf, objv[2]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 Tcl_SetResult(interp, _("not implemented yet"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 if (flags & FL_UPDATE_CURBUF)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 redraw_curbuf_later(NOT_VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917 curbuf = savebuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 curwin = savewin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 if (flags & FL_ADJUST_CURSOR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 check_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 if (flags & (FL_UPDATE_SCREEN | FL_UPDATE_CURBUF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 update_screen(NOT_VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 return err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 * This function implements the window commands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
931 winselfcmd(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
932 ClientData ref,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
933 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
934 int objc,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
935 Tcl_Obj *CONST objv[])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 int err, idx, flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 int val1, val2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 Tcl_Obj *resobj;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 win_T *savewin, *win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941 buf_T *savebuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942 char *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 enum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 WIN_BUFFER, WIN_COMMAND, WIN_CURSOR, WIN_DELCMD, WIN_EXPR,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 WIN_HEIGHT, WIN_OPTION
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 };
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 7
diff changeset
949 static CONST84 char *winoptions[] =
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951 "buffer", "command", "cursor", "delcmd", "expr",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 "height", "option", (char *)0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955 if (objc < 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961 err = Tcl_GetIndexFromObj(interp, objv[1], winoptions, "option", 0, &idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 win = (win_T *)((struct ref *)ref)->vimobj;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966 savewin = curwin; curwin = win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967 savebuf = curbuf; curbuf = win->w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 flags = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 switch (idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972 case WIN_OPTION:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 err = tclsetoption(interp, objc, objv, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974 flags |= FL_UPDATE_SCREEN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
975 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977 case WIN_COMMAND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978 err = tcldoexcommand(interp, objc, objv, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979 flags |= FL_UPDATE_SCREEN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 case WIN_EXPR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 err = tclvimexpr(interp, objc, objv, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
985
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
986 case WIN_HEIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987 if (objc == 3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989 err = Tcl_GetIntFromObj(interp, objv[2], &val1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 need_mouse_correct = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 win_setheight(val1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 err = vimerror(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 if (objc != 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 Tcl_WrongNumArgs(interp, 2, objv, "?value?");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 resobj = Tcl_NewIntObj((int)(win->w_height));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 Tcl_SetObjResult(interp, resobj);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 case WIN_BUFFER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 if (objc != 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 Tcl_WrongNumArgs(interp, 2, objv, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019 str = tclgetbuffer(interp, win->w_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 if (str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 Tcl_SetResult(interp, str, TCL_VOLATILE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 case WIN_DELCMD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 if (objc != 3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029 Tcl_WrongNumArgs(interp, 2, objv, "command");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 }
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 274
diff changeset
1033 err = tclsetdelcmd(interp, win->w_tcl_ref, (void *)win, objv[2]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036 case WIN_CURSOR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 if (objc > 4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 Tcl_WrongNumArgs(interp, 2, objv, "?arg1 ?arg2??");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 if (objc == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045 char buf[64];
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 135
diff changeset
1046
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 sprintf(buf, _("row %d column %d"), (int)row2tcl(win->w_cursor.lnum), (int)col2tcl(win->w_cursor.col));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 Tcl_SetResult(interp, buf, TCL_VOLATILE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 else if (objc == 3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 Tcl_Obj *part, *var;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 part = Tcl_NewStringObj("row", -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056 var = Tcl_ObjGetVar2(interp, objv[2], part, TCL_LEAVE_ERR_MSG);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 if (var == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 err = tclgetlinenum(interp, var, &val1, win->w_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 part = Tcl_NewStringObj("column", -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066 var = Tcl_ObjGetVar2(interp, objv[2], part, TCL_LEAVE_ERR_MSG);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 if (var == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072 err = Tcl_GetIntFromObj(interp, var, &val2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1076 else { // objc == 4
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 err = tclgetlinenum(interp, objv[2], &val1, win->w_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 err = Tcl_GetIntFromObj(interp, objv[3], &val2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1084 // TODO: should check column
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 win->w_cursor.lnum = val1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 win->w_cursor.col = col2vim(val2);
14395
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14264
diff changeset
1087 win->w_set_curswant = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 flags |= FL_UPDATE_SCREEN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 Tcl_SetResult(interp, _("not implemented yet"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 curwin = savewin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 curbuf = savebuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 if (flags & FL_UPDATE_SCREEN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 update_screen(NOT_VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 return err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1106 commandcmd(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1107 ClientData dummy UNUSED,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1108 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1109 int objc,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1110 Tcl_Obj *CONST objv[])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 int err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 err = tcldoexcommand(interp, objc, objv, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115 update_screen(VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 return err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1120 optioncmd(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1121 ClientData dummy UNUSED,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1122 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1123 int objc,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1124 Tcl_Obj *CONST objv[])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 int err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 err = tclsetoption(interp, objc, objv, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 update_screen(VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 return err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1134 exprcmd(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1135 ClientData dummy UNUSED,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1136 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1137 int objc,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1138 Tcl_Obj *CONST objv[])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 return tclvimexpr(interp, objc, objv, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1143 /////////////////////////////////////////////////////////////////////////////
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1144 // Support functions for Tcl commands
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1145 ////////////////////////////////////////////////////////////////////////////
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 * Get a line number from 'obj' and convert it to vim's range.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1151 tclgetlinenum(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1152 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1153 Tcl_Obj *obj,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1154 int *valueP,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1155 buf_T *buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 int err, i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 enum { LN_BEGIN, LN_BOTTOM, LN_END, LN_FIRST, LN_LAST, LN_START, LN_TOP };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 7
diff changeset
1161 static CONST84 char *keyw[] =
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 "begin", "bottom", "end", "first", "last", "start", "top", (char *)0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 err = Tcl_GetIndexFromObj(interp, obj, keyw, "", 0, &i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 if (err == TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 switch (i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 case LN_BEGIN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 case LN_FIRST:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 case LN_START:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 case LN_TOP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 *valueP = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 case LN_BOTTOM:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 case LN_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 case LN_LAST:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 *valueP = buf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 return TCL_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 Tcl_ResetResult(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 err = Tcl_GetIntFromObj(interp, obj, &i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 return err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 i = row2vim(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 if (i < 1 || i > buf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 Tcl_SetResult(interp, _("line number out of range"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 *valueP = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 return TCL_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 * Find the first window in the window list that displays the buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 static win_T *
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1204 tclfindwin(buf_T *buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 win_T *win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 FOR_ALL_WINDOWS(win)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 if (win->w_buffer == buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 return win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1213 return curwin; // keep current window context
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 * Do-it-all function for "::vim::command", "$buf command" and "$win command".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1220 tcldoexcommand(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1221 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1222 int objc,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1223 Tcl_Obj *CONST objv[],
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1224 int objn)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 tcl_info saveinfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 int err, flag, nobjs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 char *arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 nobjs = objc - objn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 if (nobjs < 1 || nobjs > 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 Tcl_WrongNumArgs(interp, objn, objv, "?-quiet? exCommand");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 flag = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 if (nobjs == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 arg = Tcl_GetStringFromObj(objv[objn], NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 if (strcmp(arg, "-quiet") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 flag = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 Tcl_ResetResult(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 Tcl_AppendResult(interp, _("unknown flag: "), arg, (char *)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 ++objn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 memcpy(&saveinfo, &tclinfo, sizeof(tcl_info));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 tclinfo.interp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 tclinfo.curwin = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 tclinfo.curbuf = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 arg = Tcl_GetStringFromObj(objv[objn], NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 if (flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 ++emsg_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 do_cmdline_cmd((char_u *)arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 if (flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 --emsg_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 err = vimerror(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1265 // If the ex command created a new Tcl interpreter, remove it
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 if (tclinfo.interp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 tcldelthisinterp();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 memcpy(&tclinfo, &saveinfo, sizeof(tcl_info));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 tclupdatevars();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 return err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 * Do-it-all function for "::vim::option", "$buf option" and "$win option".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1278 tclsetoption(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1279 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1280 int objc,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1281 Tcl_Obj *CONST objv[],
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1282 int objn)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 int err, nobjs, idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 char_u *option;
23424
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1286 getoption_T gov;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 long lval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 char_u *sval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 Tcl_Obj *resobj;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 enum { OPT_OFF, OPT_ON, OPT_TOGGLE };
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 7
diff changeset
1292 static CONST84 char *optkw[] = { "off", "on", "toggle", (char *)0 };
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 nobjs = objc - objn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 if (nobjs != 1 && nobjs != 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1297 Tcl_WrongNumArgs(interp, objn, objv, "vimOption ?value?");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 option = (char_u *)Tcl_GetStringFromObj(objv[objn], NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302 ++objn;
23424
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1303 gov = get_option_value(option, &lval, &sval, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 err = TCL_OK;
23424
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1305 switch (gov)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 {
23424
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1307 case gov_string:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308 Tcl_SetResult(interp, (char *)sval, TCL_VOLATILE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1309 vim_free(sval);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310 break;
23424
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1311 case gov_bool:
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1312 case gov_number:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 resobj = Tcl_NewLongObj(lval);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 Tcl_SetObjResult(interp, resobj);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 Tcl_SetResult(interp, _("unknown vimOption"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 if (nobjs == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 {
23424
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1322 if (gov != gov_string)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1324 sval = NULL; // avoid compiler warning
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325 err = Tcl_GetIndexFromObj(interp, objv[objn], optkw, "", 0, &idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 Tcl_ResetResult(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 err = Tcl_GetLongFromObj(interp, objv[objn], &lval);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332 {
23424
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1333 switch (idx)
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1334 {
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1335 case OPT_ON:
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1336 lval = 1;
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1337 break;
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1338 case OPT_OFF:
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1339 lval = 0;
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1340 break;
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1341 case OPT_TOGGLE:
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1342 lval = !lval;
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1343 break;
c0880eafe162 patch 8.2.2255: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1344 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 sval = (char_u *)Tcl_GetStringFromObj(objv[objn], NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 if (err == TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351 set_option_value(option, lval, sval, OPT_LOCAL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352 err = vimerror(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 return err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1358 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 * Do-it-all function for "::vim::expr", "$buf expr" and "$win expr".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1362 tclvimexpr(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1363 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1364 int objc,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1365 Tcl_Obj *CONST objv[],
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1366 int objn)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 char *expr, *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 int err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 if (objc - objn != 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 Tcl_WrongNumArgs(interp, objn, objv, "vimExpr");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 expr = Tcl_GetStringFromObj(objv[objn], NULL);
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
1381 str = (char *)eval_to_string((char_u *)expr, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 if (str == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383 Tcl_SetResult(interp, _("invalid expression"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 else
14264
534836186b15 patch 8.1.0148: memory leak when using :tcl expr command
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
1385 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 Tcl_SetResult(interp, str, TCL_VOLATILE);
14264
534836186b15 patch 8.1.0148: memory leak when using :tcl expr command
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
1387 vim_free(str);
534836186b15 patch 8.1.0148: memory leak when using :tcl expr command
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
1388 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 err = vimerror(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 Tcl_SetResult(interp, _("expressions disabled at compile time"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 return err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 * Check for internal vim errors.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1402 vimerror(Tcl_Interp *interp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 Tcl_SetResult(interp, _("keyboard interrupt"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409 else if (did_emsg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410 {
20369
6e1e4d7a7b39 patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
1411 Tcl_SetResult(interp, _("Vim error"), TCL_STATIC);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414 return TCL_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 * Functions that handle the reference lists:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 * delref() - callback for Tcl's DeleteCommand
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420 * tclgetref() - find/create Tcl command for a win_T* or buf_T* object
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 * tclgetwindow() - window frontend for tclgetref()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422 * tclgetbuffer() - buffer frontend for tclgetref()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 * tclsetdelcmd() - add Tcl callback command to a vim object
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 static void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1426 delref(ClientData cref)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428 struct ref *ref = (struct ref *)cref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 if (ref->delcmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 Tcl_DecrRefCount(ref->delcmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 ref->delcmd = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 ref->interp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438 static char *
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1439 tclgetref(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1440 Tcl_Interp *interp,
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1441 void **refstartP, // ptr to w_tcl_ref/b_tcl-ref member of
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1442 // win_T/buf_T struct
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1443 char *prefix, // "win" or "buf"
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1444 void *vimobj, // win_T* or buf_T*
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1445 Tcl_ObjCmdProc *proc) // winselfcmd or bufselfcmd
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1446 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447 struct ref *ref, *unused = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 static char name[VARNAME_SIZE];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449 Tcl_Command cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 ref = (struct ref *)(*refstartP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452 if (ref == &refsdeleted)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454 Tcl_SetResult(interp, _("cannot create buffer/window command: object is being deleted"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 while (ref != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1459 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460 if (ref->interp == interp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462 if (ref->interp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1463 unused = ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1464 ref = ref->next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467 if (ref)
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 135
diff changeset
1468 vim_snprintf(name, sizeof(name), "::vim::%s",
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 135
diff changeset
1469 Tcl_GetCommandName(interp, ref->cmd));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1471 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1472 if (unused)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473 ref = unused;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 ref = (struct ref *)Tcl_Alloc(sizeof(struct ref));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 ref->interp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 ref->next = (struct ref *)(*refstartP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 (*refstartP) = (void *)ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1482 // This might break on some exotic systems...
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 135
diff changeset
1483 vim_snprintf(name, sizeof(name), "::vim::%s_%lx",
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 135
diff changeset
1484 prefix, (unsigned long)vimobj);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 cmd = Tcl_CreateObjCommand(interp, name, proc,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 (ClientData)ref, (Tcl_CmdDeleteProc *)delref);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 if (!cmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 ref->interp = interp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 ref->cmd = cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492 ref->delcmd = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 ref->vimobj = vimobj;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495 return name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 static char *
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1499 tclgetwindow(Tcl_Interp *interp, win_T *win)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 274
diff changeset
1501 return tclgetref(interp, &(win->w_tcl_ref), "win", (void *)win, winselfcmd);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 static char *
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1505 tclgetbuffer(Tcl_Interp *interp, buf_T *buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 274
diff changeset
1507 return tclgetref(interp, &(buf->b_tcl_ref), "buf", (void *)buf, bufselfcmd);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1511 tclsetdelcmd(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1512 Tcl_Interp *interp,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1513 struct ref *reflist,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1514 void *vimobj,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1515 Tcl_Obj *delcmd)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1516 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517 if (reflist == &refsdeleted)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1518 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519 Tcl_SetResult(interp, _("cannot register callback command: buffer/window is already being deleted"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 while (reflist != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1525 if (reflist->interp == interp && reflist->vimobj == vimobj)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1527 if (reflist->delcmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528 Tcl_DecrRefCount(reflist->delcmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 Tcl_IncrRefCount(delcmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 reflist->delcmd = delcmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531 return TCL_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 reflist = reflist->next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1535 // This should never happen. Famous last word?
24930
b7585162b184 patch 8.2.3002: Vim doesn't abort on a fatal Tcl error
Bram Moolenaar <Bram@vim.org>
parents: 23424
diff changeset
1536 iemsg(_("E280: TCL FATAL ERROR: reflist corrupt!? Please report this to vim-dev@vim.org"));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537 Tcl_SetResult(interp, _("cannot register callback command: buffer/window reference not found"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538 return TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1542 ////////////////////////////////////////////
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1543 // I/O Channel
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1544 ////////////////////////////////////////////
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1547 tcl_channel_close(ClientData instance, Tcl_Interp *interp UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549 int err = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1550
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1551 // currently does nothing
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553 if (instance != VIMOUT && instance != VIMERR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 Tcl_SetErrno(EBADF);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1556 err = EBADF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 return err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1562 tcl_channel_input(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1563 ClientData instance UNUSED,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1564 char *buf UNUSED,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1565 int bufsiz UNUSED,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1566 int *errptr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1569 // input is currently not supported
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 Tcl_SetErrno(EINVAL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 if (errptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 *errptr = EINVAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1578 tcl_channel_output(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1579 ClientData instance,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1580 const char *buf,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1581 int bufsiz,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1582 int *errptr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 int result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1587 // The buffer is not guaranteed to be 0-terminated, and we don't if
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1588 // there is enough room to add a '\0'. So we have to create a copy
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1589 // of the buffer...
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 str = vim_strnsave((char_u *)buf, bufsiz);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 if (!str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 Tcl_SetErrno(ENOMEM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 if (errptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 *errptr = ENOMEM;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 result = bufsiz;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 if (instance == VIMOUT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 tclmsg((char *)str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 if (instance == VIMERR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 tclerrmsg((char *)str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 Tcl_SetErrno(EBADF);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 if (errptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 *errptr = EBADF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 result = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 vim_free(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 return result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 static void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1617 tcl_channel_watch(ClientData instance UNUSED, int mask UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 Tcl_SetErrno(EINVAL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1623 tcl_channel_gethandle(
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1624 ClientData instance UNUSED,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1625 int direction UNUSED,
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1626 ClientData *handleptr UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 Tcl_SetErrno(EINVAL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 return EINVAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632
7776
d30f4f9b1024 commit https://github.com/vim/vim/commit/0d6f835683bede8bfa171c2518dce10832eb8226
Christian Brabandt <cb@256bit.org>
parents: 7564
diff changeset
1633 static Tcl_ChannelType tcl_channel_type =
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1635 "vimmessage", // typeName
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1636 TCL_CHANNEL_VERSION_2, // version
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1637 tcl_channel_close, // closeProc
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1638 tcl_channel_input, // inputProc
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1639 tcl_channel_output, // outputProc
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1640 NULL, // seekProc
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1641 NULL, // setOptionProc
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1642 NULL, // getOptionProc
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1643 tcl_channel_watch, // watchProc
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1644 tcl_channel_gethandle, // getHandleProc
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1645 NULL, // close2Proc
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1646 NULL, // blockModeProc
1890
2928a6b338c3 updated for version 7.2-187
vimboss
parents: 1889
diff changeset
1647 #ifdef TCL_CHANNEL_VERSION_2
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1648 NULL, // flushProc
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1649 NULL, // handlerProc
1890
2928a6b338c3 updated for version 7.2-187
vimboss
parents: 1889
diff changeset
1650 #endif
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1651 // The following should not be necessary since TCL_CHANNEL_VERSION_2 was
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1652 // set above
1890
2928a6b338c3 updated for version 7.2-187
vimboss
parents: 1889
diff changeset
1653 #ifdef TCL_CHANNEL_VERSION_3
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1654 NULL, // wideSeekProc
1890
2928a6b338c3 updated for version 7.2-187
vimboss
parents: 1889
diff changeset
1655 #endif
2928a6b338c3 updated for version 7.2-187
vimboss
parents: 1889
diff changeset
1656 #ifdef TCL_CHANNEL_VERSION_4
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1657 NULL, // threadActionProc
1890
2928a6b338c3 updated for version 7.2-187
vimboss
parents: 1889
diff changeset
1658 #endif
2928a6b338c3 updated for version 7.2-187
vimboss
parents: 1889
diff changeset
1659 #ifdef TCL_CHANNEL_VERSION_5
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1660 NULL // truncateProc
1890
2928a6b338c3 updated for version 7.2-187
vimboss
parents: 1889
diff changeset
1661 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1664 ///////////////////////////////////
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1665 // Interface to vim
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1666 //////////////////////////////////
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 static void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1669 tclupdatevars(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1671 char varname[VARNAME_SIZE]; // must be writeable
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 char *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 strcpy(varname, VAR_RANGE1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675 Tcl_UpdateLinkedVar(tclinfo.interp, varname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 strcpy(varname, VAR_RANGE2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 Tcl_UpdateLinkedVar(tclinfo.interp, varname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 strcpy(varname, VAR_RANGE3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 Tcl_UpdateLinkedVar(tclinfo.interp, varname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681 strcpy(varname, VAR_LBASE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 Tcl_UpdateLinkedVar(tclinfo.interp, varname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 name = tclgetbuffer(tclinfo.interp, curbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 strcpy(tclinfo.curbuf, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 strcpy(varname, VAR_CURBUF);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 Tcl_UpdateLinkedVar(tclinfo.interp, varname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 name = tclgetwindow(tclinfo.interp, curwin);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 strcpy(tclinfo.curwin, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 strcpy(varname, VAR_CURWIN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 Tcl_UpdateLinkedVar(tclinfo.interp, varname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1697 tclinit(exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1699 char varname[VARNAME_SIZE]; // Tcl_LinkVar requires writeable varname
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 char *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 #ifdef DYNAMIC_TCL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 if (!tcl_enabled(TRUE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15034
diff changeset
1705 emsg(_("E571: Sorry, this command is disabled: the Tcl library could not be loaded."));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 if (!tclinfo.interp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 Tcl_Interp *interp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 static Tcl_Channel ch1, ch2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1715 // Create replacement channels for stdout and stderr; this has to be
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1716 // done each time an interpreter is created since the channels are closed
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1717 // when the interpreter is deleted
7776
d30f4f9b1024 commit https://github.com/vim/vim/commit/0d6f835683bede8bfa171c2518dce10832eb8226
Christian Brabandt <cb@256bit.org>
parents: 7564
diff changeset
1718 ch1 = Tcl_CreateChannel(&tcl_channel_type, "vimout", VIMOUT, TCL_WRITABLE);
d30f4f9b1024 commit https://github.com/vim/vim/commit/0d6f835683bede8bfa171c2518dce10832eb8226
Christian Brabandt <cb@256bit.org>
parents: 7564
diff changeset
1719 ch2 = Tcl_CreateChannel(&tcl_channel_type, "vimerr", VIMERR, TCL_WRITABLE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 Tcl_SetStdChannel(ch1, TCL_STDOUT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 Tcl_SetStdChannel(ch2, TCL_STDERR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 interp = Tcl_CreateInterp();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724 Tcl_Preserve(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 if (Tcl_Init(interp) == TCL_ERROR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727 Tcl_Release(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 Tcl_DeleteInterp(interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1731 #if 0
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1732 // VIM sure is interactive
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733 Tcl_SetVar(interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 Tcl_SetChannelOption(interp, ch1, "-buffering", "line");
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1737 #ifdef MSWIN
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1738 Tcl_SetChannelOption(interp, ch1, "-translation", "lf");
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1739 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 Tcl_SetChannelOption(interp, ch2, "-buffering", "line");
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1741 #ifdef MSWIN
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1742 Tcl_SetChannelOption(interp, ch2, "-translation", "lf");
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1743 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1745 // replace standard Tcl exit command
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 Tcl_DeleteCommand(interp, "exit");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 Tcl_CreateObjCommand(interp, "exit", exitcmd,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1750 // new commands, in ::vim namespace
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 Tcl_CreateObjCommand(interp, "::vim::buffer", buffercmd,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 Tcl_CreateObjCommand(interp, "::vim::window", windowcmd,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 Tcl_CreateObjCommand(interp, "::vim::command", commandcmd,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1757 Tcl_CreateObjCommand(interp, "::vim::beep", beepcmd,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 Tcl_CreateObjCommand(interp, "::vim::option", optioncmd,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 Tcl_CreateObjCommand(interp, "::vim::expr", exprcmd,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1764 // "lbase" variable
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 tclinfo.lbase = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766 strcpy(varname, VAR_LBASE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 Tcl_LinkVar(interp, varname, (char *)&tclinfo.lbase, TCL_LINK_INT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1769 // "range" variable
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 tclinfo.range_start = eap->line1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771 strcpy(varname, VAR_RANGE1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 Tcl_LinkVar(interp, varname, (char *)&tclinfo.range_start, TCL_LINK_INT|TCL_LINK_READ_ONLY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 strcpy(varname, VAR_RANGE2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 Tcl_LinkVar(interp, varname, (char *)&tclinfo.range_start, TCL_LINK_INT|TCL_LINK_READ_ONLY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 tclinfo.range_end = eap->line2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 strcpy(varname, VAR_RANGE3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 Tcl_LinkVar(interp, varname, (char *)&tclinfo.range_end, TCL_LINK_INT|TCL_LINK_READ_ONLY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1779 // "current" variable
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 tclinfo.curbuf = Tcl_Alloc(VARNAME_SIZE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 tclinfo.curwin = Tcl_Alloc(VARNAME_SIZE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 name = tclgetbuffer(interp, curbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 strcpy(tclinfo.curbuf, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 strcpy(varname, VAR_CURBUF);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 Tcl_LinkVar(interp, varname, (char *)&tclinfo.curbuf, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 name = tclgetwindow(interp, curwin);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 strcpy(tclinfo.curwin, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 strcpy(varname, VAR_CURWIN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789 Tcl_LinkVar(interp, varname, (char *)&tclinfo.curwin, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 tclinfo.interp = interp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1795 // Interpreter already exists, just update variables
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 tclinfo.range_start = row2tcl(eap->line1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 tclinfo.range_end = row2tcl(eap->line2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 tclupdatevars();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 }
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1800
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1801 tclinfo.exitvalue = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 static void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1806 tclerrmsg(char *text)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 char *next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 while ((next=strchr(text, '\n')))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 *next++ = '\0';
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15034
diff changeset
1813 emsg(text);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 text = next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816 if (*text)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15034
diff changeset
1817 emsg(text);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 static void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1821 tclmsg(char *text)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 char *next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 while ((next=strchr(text, '\n')))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 *next++ = '\0';
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1828 msg(text);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 text = next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 if (*text)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1832 msg(text);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 static void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1836 tcldelthisinterp(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 if (!Tcl_InterpDeleted(tclinfo.interp))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 Tcl_DeleteInterp(tclinfo.interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 Tcl_Release(tclinfo.interp);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1841 // The interpreter is now gets deleted. All registered commands (esp.
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1842 // window and buffer commands) are deleted, triggering their deletion
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1843 // callback, which deletes all refs pointing to this interpreter.
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1844 // We could garbage-collect the unused ref structs in all windows and
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1845 // buffers, but unless the user creates hundreds of sub-interpreters
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1846 // all referring to lots of windows and buffers, this is hardly worth
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1847 // the effort. Unused refs are recycled by other interpreters, and
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1848 // all refs are free'd when the window/buffer gets closed by vim.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850 tclinfo.interp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 Tcl_Free(tclinfo.curbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 Tcl_Free(tclinfo.curwin);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 tclinfo.curbuf = tclinfo.curwin = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 static int
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1857 tclexit(int error)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859 int newerr = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1861 if (Tcl_InterpDeleted(tclinfo.interp) // True if we intercepted Tcl's exit command
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1862 #if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 5) || TCL_MAJOR_VERSION > 8
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1863 || Tcl_LimitExceeded(tclinfo.interp) // True if the interpreter cannot continue
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1864 #endif
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1865 )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 {
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 135
diff changeset
1867 char buf[50];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1869 sprintf(buf, _("E572: exit code %d"), tclinfo.exitvalue);
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1870 tclerrmsg(buf);
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1871 if (tclinfo.exitvalue == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 {
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1873 did_emsg = 0;
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1874 newerr = OK;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 else
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1877 newerr = FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 tcldelthisinterp();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 char *result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 7
diff changeset
1885 result = (char *)Tcl_GetStringResult(tclinfo.interp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 if (error == TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888 tclmsg(result);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889 newerr = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 tclerrmsg(result);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 newerr = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1898 return newerr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 * ":tcl"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904 void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1905 ex_tcl(exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907 char_u *script;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 int err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 script = script_get(eap, eap->arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 if (!eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 err = tclinit(eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914 if (err == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916 Tcl_AllowExceptions(tclinfo.interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 if (script == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 err = Tcl_Eval(tclinfo.interp, (char *)eap->arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920 err = Tcl_Eval(tclinfo.interp, (char *)script);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1921 err = tclexit(err);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924 vim_free(script);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1925 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1928 * ":tclfile"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1931 ex_tclfile(exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1932 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 char *file = (char *)eap->arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 int err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 err = tclinit(eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 if (err == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 Tcl_AllowExceptions(tclinfo.interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940 err = Tcl_EvalFile(tclinfo.interp, file);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941 err = tclexit(err);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1946 * ":tcldo"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948 void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
1949 ex_tcldo(exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1950 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951 char *script, *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 int err, rs, re, lnum;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1953 char var_lnum[VARNAME_SIZE]; // must be writeable memory
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 char var_line[VARNAME_SIZE];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 linenr_T first_line = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956 linenr_T last_line = 0;
10763
ae0bbbbe2a38 patch 8.0.0271: may get ml_get error when :tcldo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
1957 buf_T *was_curbuf = curbuf;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959 rs = eap->line1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1960 re = eap->line2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961 script = (char *)eap->arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1962 strcpy(var_lnum, VAR_CURLNUM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963 strcpy(var_line, VAR_CURLINE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 err = tclinit(eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1966 if (err != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969 lnum = row2tcl(rs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 Tcl_LinkVar(tclinfo.interp, var_lnum, (char *)&lnum, TCL_LINK_INT|TCL_LINK_READ_ONLY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1971 err = TCL_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1972 if (u_save((linenr_T)(rs-1), (linenr_T)(re+1)) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1973 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 Tcl_SetResult(tclinfo.interp, _("cannot save undo information"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 while (err == TCL_OK && rs <= re)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1978 {
10763
ae0bbbbe2a38 patch 8.0.0271: may get ml_get error when :tcldo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
1979 if ((linenr_T)rs > curbuf->b_ml.ml_line_count)
ae0bbbbe2a38 patch 8.0.0271: may get ml_get error when :tcldo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
1980 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1981 line = (char *)ml_get_buf(curbuf, (linenr_T)rs, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982 if (!line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984 Tcl_SetResult(tclinfo.interp, _("cannot get line"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988 Tcl_SetVar(tclinfo.interp, var_line, line, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 Tcl_AllowExceptions(tclinfo.interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 err = Tcl_Eval(tclinfo.interp, script);
3369
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1991 if (err != TCL_OK
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1992 || Tcl_InterpDeleted(tclinfo.interp)
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1993 #if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 5) || TCL_MAJOR_VERSION > 8
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1994 || Tcl_LimitExceeded(tclinfo.interp)
045fdc5b6056 updated for version 7.3.451
Bram Moolenaar <bram@vim.org>
parents: 2982
diff changeset
1995 #endif
10763
ae0bbbbe2a38 patch 8.0.0271: may get ml_get error when :tcldo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
1996 || curbuf != was_curbuf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1997 break;
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 7
diff changeset
1998 line = (char *)Tcl_GetVar(tclinfo.interp, var_line, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1999 if (line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2000 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 if (ml_replace((linenr_T)rs, (char_u *)line, TRUE) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2003 Tcl_SetResult(tclinfo.interp, _("cannot replace line"), TCL_STATIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 err = TCL_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2006 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 if (first_line == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 first_line = rs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2009 last_line = rs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2010 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2011 ++rs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2012 ++lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2013 Tcl_UpdateLinkedVar(tclinfo.interp, var_lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2014 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2015 if (first_line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2016 changed_lines(first_line, 0, last_line + 1, (long)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018 Tcl_UnsetVar(tclinfo.interp, var_line, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2019 Tcl_UnlinkVar(tclinfo.interp, var_lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2020 if (err == TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2021 Tcl_ResetResult(tclinfo.interp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2022
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023 (void)tclexit(err);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2025
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2026 static void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
2027 tcldelallrefs(struct ref *ref)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 struct ref *next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2030 int err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2031 char *result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2032
7564
aee06f1762e0 commit https://github.com/vim/vim/commit/858b96f382eeb8f1eab5100639e7b09523a6a2a1
Christian Brabandt <cb@256bit.org>
parents: 7538
diff changeset
2033 #ifdef DYNAMIC_TCL
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2034 // TODO: this code currently crashes Vim on exit
7538
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
2035 if (exiting)
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
2036 return;
7564
aee06f1762e0 commit https://github.com/vim/vim/commit/858b96f382eeb8f1eab5100639e7b09523a6a2a1
Christian Brabandt <cb@256bit.org>
parents: 7538
diff changeset
2037 #endif
7538
c9fc24b76293 commit https://github.com/vim/vim/commit/8a5115cf18751022387af2085f374d38c60dde83
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
2038
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2039 while (ref != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2040 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2041 next = ref->next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2042 if (ref->interp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2043 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2044 if (ref->delcmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2045 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2046 err = Tcl_GlobalEvalObj(ref->interp, ref->delcmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2047 if (err != TCL_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2048 {
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 7
diff changeset
2049 result = (char *)Tcl_GetStringResult(ref->interp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2050 if (result)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2051 tclerrmsg(result);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2052 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2053 Tcl_DecrRefCount(ref->delcmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054 ref->delcmd = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 Tcl_DeleteCommandFromToken(ref->interp, ref->cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2057 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2058 Tcl_Free((char *)ref);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 ref = next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2061 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2062
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2063 void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
2064 tcl_buffer_free(buf_T *buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 struct ref *reflist;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2068 #ifdef DYNAMIC_TCL
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2069 if (!stubs_initialized) // Not using Tcl, nothing to do.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2070 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2071 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2072
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 274
diff changeset
2073 reflist = (struct ref *)(buf->b_tcl_ref);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2074 if (reflist != &refsdeleted)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2075 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 274
diff changeset
2076 buf->b_tcl_ref = (void *)&refsdeleted;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2077 tcldelallrefs(reflist);
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 274
diff changeset
2078 buf->b_tcl_ref = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2079 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2080 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2081
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2082 void
7823
bcef391c101c commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents: 7776
diff changeset
2083 tcl_window_free(win_T *win)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2084 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2085 struct ref *reflist;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2086
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2087 #ifdef DYNAMIC_TCL
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2088 if (!stubs_initialized) // Not using Tcl, nothing to do.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2090 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 274
diff changeset
2092 reflist = (struct ref*)(win->w_tcl_ref);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 if (reflist != &refsdeleted)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 274
diff changeset
2095 win->w_tcl_ref = (void *)&refsdeleted;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2096 tcldelallrefs(reflist);
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 274
diff changeset
2097 win->w_tcl_ref = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2098 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2099 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2100
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2101 // The End