annotate src/if_tcl.c @ 2332:b13079093ae1 vim73

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