aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Tromey1994-04-06 22:10:06 +0000
committerTom Tromey1994-04-06 22:10:06 +0000
commit9875e64691cfdf87bd1a8b8c0d7fbc38831f8a51 (patch)
treeaa84670aaa4b32891be89a85658ae156163d24a8
parentb32a6a15af1bdc88ed07394504704b09b75c54a6 (diff)
downloademacs-9875e64691cfdf87bd1a8b8c0d7fbc38831f8a51.tar.gz
emacs-9875e64691cfdf87bd1a8b8c0d7fbc38831f8a51.zip
Initial revision
-rw-r--r--lisp/progmodes/tcl.el1815
1 files changed, 1815 insertions, 0 deletions
diff --git a/lisp/progmodes/tcl.el b/lisp/progmodes/tcl.el
new file mode 100644
index 00000000000..eb9b5808977
--- /dev/null
+++ b/lisp/progmodes/tcl.el
@@ -0,0 +1,1815 @@
1;; tcl.el -- Tcl code editing commands for Emacs
2
3;; Copyright (C) 1994 Free Software Foundation, Inc.
4
5;;; Maintainer: Tom Tromey <tromey@busco.lanl.gov>
6;;; Author: Tom Tromey <tromey@busco.lanl.gov>
7;;; Chris Lindblad <cjl@lcs.mit.edu>
8;;; Keywords: languages
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation; either version 1, or (at your option)
15;; any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs; see the file COPYING. If not, write to
24;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25
26;; HOW TO INSTALL:
27;; Put the following forms in your .emacs to enable autoloading of Tcl
28;; mode, and auto-recognition of ".tcl" files.
29;;
30;; (autoload 'tcl-mode "tcl" "Tcl mode." t)
31;; (autoload 'inferior-tcl "tcl" "Run inferior Tcl process." t)
32;; (setq auto-mode-alist (append '(("\\.tcl$" . tcl-mode)) auto-mode-alist))
33;;
34;; If you plan to use the interface to the TclX help files, you must
35;; set the variable tcl-help-directory to point to the topmost
36;; directory containing the TclX help files. Eg:
37;;
38;; (setq tcl-help-directory "/usr/local/lib/tclx/help")
39;;
40;; Also you will want to add the following to your .emacs:
41;;
42;; (autoload 'tcl-help-on-word "tcl" "Help on Tcl commands" t)
43;;
44;; FYI a *very* useful thing to do is nroff all the Tk man pages and
45;; put them in a subdir of the help system.
46;;
47
48;;; Commentary:
49
50;; LCD Archive Entry:
51;; tcl|Tom Tromey|tromey@busco.lanl.gov|
52;; Major mode for editing Tcl|
53;; 6-Apr-94|1.0|
54
55;; CUSTOMIZATION NOTES:
56;; * tcl-proc-list can be used to customize a list of things that
57;; "define" other things. Eg in my project I put "defvar" in this
58;; list.
59;; * tcl-typeword-list is similar, but uses font-lock-type-face.
60;; * tcl-keyword-list is a list of keywords. I've generally used this
61;; for flow-control words. Eg I add "unwind_protect" to this list.
62;; * tcl-type-alist can be used to minimally customize indentation
63;; according to context.
64
65;; Change log:
66;; 18-Mar-1994 Tom Tromey Fourth beta release.
67;; Added {un,}comment-region to menu. Idea from
68;; Mike Scheidler <c23mts@kocrsv01.delcoelect.com>
69;; 17-Mar-1994 Tom Tromey
70;; Fixed tcl-restart-with-file. Bug fix attempt in
71;; tcl-internal-end-of-defun.
72;; 16-Mar-1994 Tom Tromey Third beta release
73;; Added support code for menu (from Tcl mode written by
74;; schmid@fb3-s7.math.TU-Berlin.DE (Gregor Schmid)).
75;; 12-Mar-1994 Tom Tromey
76;; Better documentation for inferior-tcl-buffer. Wrote
77;; tcl-restart-with-file. Wrote Lucid Emacs menu (but no
78;; code to install it).
79;; 12-Mar-1994 Tom Tromey
80;; Wrote tcl-guess-application. Another stab at making
81;; tcl-omit-ws-regexp work.
82;; 10-Mar-1994 Tom Tromey Second beta release
83;; Last Modified: Thu Mar 10 01:24:25 1994 (Tom Tromey)
84;; Wrote perl-mode style line indentation command.
85;; Wrote more documentation. Added tcl-continued-indent-level.
86;; Integrated help code.
87;; 8-Mar-1994 Tom Tromey
88;; Last Modified: Tue Mar 8 11:58:44 1994 (Tom Tromey)
89;; Bug fixes.
90;; 6-Mar-1994 Tom Tromey
91;; Last Modified: Sun Mar 6 18:55:41 1994 (Tom Tromey)
92;; Updated auto-newline support.
93;; 6-Mar-1994 Tom Tromey Beta release
94;; Last Modified: Sat Mar 5 17:24:32 1994 (Tom Tromey)
95;; Wrote tcl-hashify-buffer. Other minor bug fixes.
96;; 5-Mar-1994 Tom Tromey
97;; Last Modified: Sat Mar 5 16:11:20 1994 (Tom Tromey)
98;; Wrote electric-hash code.
99;; 3-Mar-1994 Tom Tromey
100;; Last Modified: Thu Mar 3 02:53:40 1994 (Tom Tromey)
101;; Added code to handle auto-fill in comments.
102;; Added imenu support code.
103;; Cleaned up code.
104;; Better font-lock support.
105;; 28-Feb-1994 Tom Tromey
106;; Last Modified: Mon Feb 28 14:08:05 1994 (Tom Tromey)
107;; Made tcl-figure-type more easily configurable.
108;; 28-Feb-1994 Tom Tromey
109;; Last Modified: Mon Feb 28 01:02:58 1994 (Tom Tromey)
110;; Wrote inferior-tcl mode.
111;; 16-Feb-1994 Tom Tromey
112;; Last Modified: Wed Feb 16 17:05:19 1994 (Tom Tromey)
113;; Added support for font-lock-mode.
114;; 29-Oct-1993 Tom Tromey
115;; Last Modified: Sun Oct 24 17:39:14 1993 (Tom Tromey)
116;; Patches from Guido Bosch to make things work with Lucid Emacs.
117;; 22-Oct-1993 Tom Tromey
118;; Last Modified: Fri Oct 22 15:26:46 1993 (Tom Tromey)
119;; Made many characters have "_" syntax class; suggested by Guido
120;; Bosch <Guido.Bosch@loria.fr>. Note that this includes the "$"
121;; character, which might be a change you'd notice.
122;; 21-Oct-1993 Tom Tromey
123;; Last Modified: Thu Oct 21 20:28:40 1993 (Tom Tromey)
124;; More fixes for tcl-omit-ws-regexp.
125;; 20-Oct-1993 Tom Tromey
126;; Started keeping history. Fixed tcl-{beginning,end}-of-defun.
127;; Added some code to make things work with Emacs 18.
128
129;; THANKS TO:
130;; Guido Bosch <Guido.Bosch@loria.fr>
131;; pgs1002@esc.cam.ac.uk (Dr P.G. Sjoerdsma)
132;; Mike Scheidler <c23mts@kocrsv01.delcoelect.com>
133;; Matt Newman <men@charney.colorado.edu>
134;; rwhitby@research.canon.oz.au (Rod Whitby)
135;; h9118101@hkuxa.hku.hk (Yip Chi Lap [Beta])
136;; Pertti Tapio Kasanen <ptk@delta.hut.fi>
137;; schmid@fb3-s7.math.TU-Berlin.DE (Gregor Schmid)
138
139;; KNOWN BUGS:
140;; * indent-region should skip blank lines. (It does in v19, so I'm
141;; not motivated to fix it here).
142;; * In Tcl "#" is not always a comment character. This can confuse
143;; tcl.el in certain circumstances. For now the only workaround is
144;; to enclose offending hash characters in quotes or precede it with
145;; a backslash. Note that using braces won't work -- quotes change
146;; the syntax class of characters between them, while braces do not.
147;; The electric-# mode helps alleviate this problem somewhat.
148;; * indent-tcl-exp is untested.
149;; * Doesn't work under Emacs 18 yet.
150;; * There's been a report that font-lock does strange things under
151;; Lucid Emacs 19.6. For instance in "proc foobar", the space
152;; before "foobar" is highlighted.
153
154;; TODO:
155;; * make add-log-tcl-defun smarter. should notice if we are in the
156;; middle of a defun, or between defuns. should notice if point is
157;; on first line of defun (or maybe even in comments before defun).
158;; * Allow continuation lines to be indented under the first argument
159;; of the preceeding line, like this:
160;; [list something \
161;; something-else]
162;; * There is a request that indentation work like this:
163;; button .fred -label Fred \
164;; -command {puts fred}
165;; * Should have tcl-complete-symbol that queries the inferior process.
166;; * Should have describe-symbol that works by sending the magic
167;; command to a tclX process.
168;; * Need C-x C-e binding (tcl-eval-last-exp).
169;; * Write indent-region function that is faster than indenting each
170;; line individually.
171;; * tcl-figure-type should stop at "beginning of line" (only ws
172;; before point, and no "\" on previous line). (see tcl-real-command-p).
173;; * Fix beginning-of-defun. I believe this will be fully possible in
174;; FSF Emacs 19.23
175;; * overrides some comint keybindings; fix.
176;; * Trailing \ will eat blank lines. Should deal with this.
177;; (this would help catch some potential bugs).
178;; * Inferior should display in half the screen, not the whole screen.
179
180
181
182;;; Code:
183
184(require 'comint)
185
186;;
187;; User variables.
188;;
189
190(defvar tcl-indent-level 4
191 "*Indentation of Tcl statements with respect to containing block.")
192
193(defvar tcl-continued-indent-level 4
194 "*Indentation of continuation line relative to first line of command.")
195
196(defvar tcl-auto-newline nil
197 "*Non-nil means automatically newline before and after braces
198inserted in Tcl code.")
199
200(defvar tcl-tab-always-indent t
201 "*Control effect of TAB key.
202If t (the default), always indent current line.
203If nil and point is not in the indentation area at the beginning of
204the line, a TAB is inserted.
205Other values cause the first possible action from the following list
206to take place:
207
208 1. Move from beginning of line to correct indentation.
209 2. Delete an empty comment.
210 3. Move forward to start of comment, indenting if necessary.
211 4. Move forward to end of line, indenting if necessary.
212 5. Create an empty comment.
213 6. Move backward to start of comment, indenting if necessary.")
214
215(defvar tcl-use-hairy-comment-detector t
216 "*If not `nil', the the more complicated, but slower, comment
217detecting function is used. This variable is only used in GNU Emacs
21819 (the fast function is always used elsewhere).")
219
220(defvar tcl-electric-hash-style 'smart
221 "*Style of electric hash insertion to use.
222Possible values are 'backslash, meaning that `\\' quoting should be
223done; `quote, meaning that `\"' quoting should be done; 'smart,
224meaning that the choice between 'backslash and 'quote should be
225made depending on the number of hashes inserted; or nil, meaning that
226no quoting should be done. Any other value for this variable is
227taken to mean 'smart. The default is 'smart.")
228
229(defvar tcl-help-directory nil
230 "*Name of topmost directory containing TclX help files")
231
232(defvar tcl-use-smart-word-finder t
233 "*If not nil, use a better way of finding the current word when
234looking up help on a Tcl command.")
235
236(defvar tcl-application "wish"
237 "*Name of Tcl application to run in inferior Tcl mode.")
238
239(defvar tcl-command-switches nil
240 "*Switches to supply to `tcl-application'.")
241
242(defvar tcl-prompt-regexp "^\\(% \\|\\)"
243 "*If not nil, a regexp that will match the prompt in the inferior process.
244If nil, the prompt is the name of the application with \">\" appended.
245
246The default is \"^\\(% \\|\\)\", which will match the default primary
247and secondary prompts for tclsh and wish.")
248
249(defvar inferior-tcl-source-command "source %s\n"
250 "*Format-string for building a Tcl command to load a file.
251This format string should use `%s' to substitute a file name
252and should result in a Tcl expression that will command the
253inferior Tcl to load that file. The filename will be appropriately
254quoted for Tcl.")
255
256;;
257;; Keymaps, abbrevs, syntax tables.
258;;
259
260(defvar tcl-mode-abbrev-table nil
261 "Abbrev table in use in Tcl-mode buffers.")
262(if tcl-mode-abbrev-table
263 ()
264 (define-abbrev-table 'tcl-mode-abbrev-table ()))
265
266;; I sure wish Emacs had a package that made it easy to extract this
267;; sort of information.
268(defconst tcl-using-emacs-19 (string-match "19\\." emacs-version)
269 "Nil unless using Emacs 19 (Lucid or FSF).")
270
271;; FIXME this will break on Emacs 19.100.
272(defconst tcl-using-emacs-19.23
273 (string-match "19\\.\\(2[3-9]\\|[3-9][0-9]\\)" emacs-version)
274 "Nil unless using Emacs 19.23 or later.")
275
276(defconst tcl-using-lemacs-19 (string-match "Lucid" emacs-version)
277 "Nil unless using Lucid Emacs).")
278
279(defvar tcl-mode-map ()
280 "Keymap used in Tcl mode.")
281(if tcl-mode-map
282 ()
283 (setq tcl-mode-map (make-sparse-keymap))
284 (define-key tcl-mode-map "{" 'tcl-electric-char)
285 (define-key tcl-mode-map "}" 'tcl-electric-brace)
286 (define-key tcl-mode-map "[" 'tcl-electric-char)
287 (define-key tcl-mode-map "]" 'tcl-electric-char)
288 (define-key tcl-mode-map ";" 'tcl-electric-char)
289 (define-key tcl-mode-map "#" 'tcl-electric-hash)
290 ;; FIXME.
291 (define-key tcl-mode-map "\e\C-a" 'tcl-beginning-of-defun)
292 ;; FIXME.
293 (define-key tcl-mode-map "\e\C-e" 'tcl-end-of-defun)
294 ;; FIXME.
295 (define-key tcl-mode-map "\e\C-h" 'mark-tcl-function)
296 (define-key tcl-mode-map "\e\C-q" 'indent-tcl-exp)
297 (define-key tcl-mode-map "\177" 'backward-delete-char-untabify)
298 (define-key tcl-mode-map "\t" 'tcl-indent-command)
299 (define-key tcl-mode-map "\M-\C-x" 'tcl-eval-defun)
300 (and (fboundp 'comment-region)
301 (define-key tcl-mode-map "\C-c\C-c" 'comment-region))
302 (define-key tcl-mode-map "\C-c\C-d" 'tcl-help-on-word)
303 (define-key tcl-mode-map "\C-c\C-e" 'tcl-eval-defun)
304 (define-key tcl-mode-map "\C-c\C-l" 'tcl-load-file)
305 (define-key tcl-mode-map "\C-c\C-p" 'inferior-tcl)
306 (define-key tcl-mode-map "\C-c\C-r" 'tcl-eval-region)
307 (define-key tcl-mode-map "\C-c\C-z" 'switch-to-tcl))
308
309(defvar tcl-mode-syntax-table nil
310 "Syntax table in use in Tcl-mode buffers.")
311(if tcl-mode-syntax-table
312 ()
313 (setq tcl-mode-syntax-table (make-syntax-table))
314 (modify-syntax-entry ?% "_" tcl-mode-syntax-table)
315 (modify-syntax-entry ?@ "_" tcl-mode-syntax-table)
316 (modify-syntax-entry ?& "_" tcl-mode-syntax-table)
317 (modify-syntax-entry ?* "_" tcl-mode-syntax-table)
318 (modify-syntax-entry ?+ "_" tcl-mode-syntax-table)
319 (modify-syntax-entry ?- "_" tcl-mode-syntax-table)
320 (modify-syntax-entry ?. "_" tcl-mode-syntax-table)
321 (modify-syntax-entry ?: "_" tcl-mode-syntax-table)
322 (modify-syntax-entry ?! "_" tcl-mode-syntax-table)
323 (modify-syntax-entry ?$ "_" tcl-mode-syntax-table) ; FIXME use "'"?
324 (modify-syntax-entry ?/ "_" tcl-mode-syntax-table)
325 (modify-syntax-entry ?~ "_" tcl-mode-syntax-table)
326 (modify-syntax-entry ?< "_" tcl-mode-syntax-table)
327 (modify-syntax-entry ?= "_" tcl-mode-syntax-table)
328 (modify-syntax-entry ?> "_" tcl-mode-syntax-table)
329 (modify-syntax-entry ?| "_" tcl-mode-syntax-table)
330 (modify-syntax-entry ?\( "()" tcl-mode-syntax-table)
331 (modify-syntax-entry ?\) ")(" tcl-mode-syntax-table)
332 (modify-syntax-entry ?\; "." tcl-mode-syntax-table)
333 (modify-syntax-entry ?\n "> " tcl-mode-syntax-table)
334 (modify-syntax-entry ?\f "> " tcl-mode-syntax-table)
335 (modify-syntax-entry ?# "< " tcl-mode-syntax-table))
336
337(defvar inferior-tcl-mode-map nil
338 "Keymap used in Inferior Tcl mode.")
339(if inferior-tcl-mode-map
340 ()
341 ;; FIXME Use keymap inheritance here? FIXME we override comint
342 ;; keybindings here. Maybe someone has a better set?
343 (setq inferior-tcl-mode-map (copy-keymap comint-mode-map))
344 (define-key inferior-tcl-mode-map "\e\C-a" 'tcl-beginning-of-defun)
345 (define-key inferior-tcl-mode-map "\e\C-e" 'tcl-end-of-defun)
346 (define-key inferior-tcl-mode-map "\177" 'backward-delete-char-untabify)
347 (define-key inferior-tcl-mode-map "\M-\C-x" 'tcl-eval-defun)
348 (define-key inferior-tcl-mode-map "\C-c\C-d" 'tcl-help-on-word)
349 (define-key inferior-tcl-mode-map "\C-c\C-e" 'tcl-eval-defun)
350 (define-key inferior-tcl-mode-map "\C-c\C-l" 'tcl-load-file)
351 (define-key inferior-tcl-mode-map "\C-c\C-p" 'inferior-tcl)
352 (define-key inferior-tcl-mode-map "\C-c\C-r" 'tcl-eval-region)
353 (define-key inferior-tcl-mode-map "\C-c\C-z" 'switch-to-tcl))
354
355;; Lucid Emacs menu.
356(defvar tcl-lucid-menu
357 '("Tcl"
358 ["Beginning of function" tcl-beginning-of-defun t]
359 ["End of function" tcl-end-of-defun t]
360 ["Mark function" mark-tcl-function t]
361 ["Indent region" indent-region t]
362 ["Comment region" comment-region t]
363 ["Uncomment region" tcl-uncomment-region t]
364 "----"
365 ["Show Tcl process buffer" inferior-tcl t]
366 ["Send function to Tcl process" tcl-eval-defun t]
367 ["Send region to Tcl process" tcl-eval-region t]
368 ["Send file to Tcl process" tcl-load-file t]
369 ["Restart Tcl process with file" tcl-restart-with-file t]
370 "----"
371 ["Tcl help" tcl-help-on-word t]))
372
373(defvar inferior-tcl-buffer nil
374 "*The current inferior-tcl process buffer.
375
376MULTIPLE PROCESS SUPPORT
377===========================================================================
378To run multiple Tcl processes, you start the first up with
379\\[inferior-tcl]. It will be in a buffer named `*inferior-tcl*'.
380Rename this buffer with \\[rename-buffer]. You may now start up a new
381process with another \\[inferior-tcl]. It will be in a new buffer,
382named `*inferior-tcl*'. You can switch between the different process
383buffers with \\[switch-to-buffer].
384
385Commands that send text from source buffers to Tcl processes -- like
386`tcl-eval-defun' or `tcl-load-file' -- have to choose a process to
387send to, when you have more than one Tcl process around. This is
388determined by the global variable `inferior-tcl-buffer'. Suppose you
389have three inferior Lisps running:
390 Buffer Process
391 foo inferior-tcl
392 bar inferior-tcl<2>
393 *inferior-tcl* inferior-tcl<3>
394If you do a \\[tcl-eval-defun] command on some Lisp source code, what
395process do you send it to?
396
397- If you're in a process buffer (foo, bar, or *inferior-tcl*),
398 you send it to that process.
399- If you're in some other buffer (e.g., a source file), you
400 send it to the process attached to buffer `inferior-tcl-buffer'.
401This process selection is performed by function `inferior-tcl-proc'.
402
403Whenever \\[inferior-tcl] fires up a new process, it resets
404`inferior-tcl-buffer' to be the new process's buffer. If you only run
405one process, this does the right thing. If you run multiple
406processes, you can change `inferior-tcl-buffer' to another process
407buffer with \\[set-variable].")
408
409;;
410;; Hooks and other customization.
411;;
412
413(defvar tcl-mode-hook nil
414 "Hook run on entry to Tcl mode.
415
416Several functions exist which are useful to run from your
417`tcl-mode-hook' (see each function's documentation for more
418information):
419
420 tcl-install-menubar
421 Puts a \"Tcl\" menu on the menubar. Doesn't work in Emacs 18.
422 tcl-guess-application
423 Guesses a default setting for `tcl-application' based on any
424 \"#!\" line at the top of the file.
425 tcl-hashify-buffer
426 Quotes all \"#\" characters that don't correspond to actual
427 Tcl comments. (Useful when editing code not originally created
428 with this mode).
429 tcl-auto-fill-mode
430 Auto-filling of Tcl comments.
431
432Emacs 19 users can add functions to the hook with `add-hook':
433
434 (add-hook 'tcl-mode-hook 'tcl-guess-application)
435
436Emacs 18 users must use `setq':
437
438 (setq tcl-mode-hook (cons 'tcl-guess-application tcl-mode-hook))")
439
440
441(defvar inferior-tcl-mode-hook nil
442 "Hook for customizing Inferior Tcl mode.")
443
444(defvar tcl-proc-list
445 '("proc")
446 "List of commands whose first argument defines something.
447This exists because some people (eg, me) use \"defvar\" et al.
448Call `tcl-set-proc-regexp' and `tcl-set-font-lock-keywords'
449after changing this list.")
450
451(defvar tcl-proc-regexp nil
452 "Regexp to use when matching proc headers.")
453
454(defvar tcl-typeword-list
455 '("global" "upvar")
456 "List of Tcl keywords deonting \"type\". Used only for highlighting.
457Call `tcl-set-font-lock-keywords' after changing this list.")
458
459;; Generally I've picked control operators to be keywords.
460(defvar tcl-keyword-list
461 '("if" "then" "else" "elseif" "for" "foreach" "break" "continue" "while"
462 "eval" "case" "in" "switch" "default" "exit" "error" "proc" "return"
463 "uplevel" "loop" "for_array_keys" "for_recursive_glob" "for_file")
464 "List of Tcl keywords. Used only for highlighting.
465Default list includes some TclX keywords.
466Call `tcl-set-font-lock-keywords' after changing this list.")
467
468(defvar tcl-font-lock-keywords nil
469 "Keywords to highlight for Tcl. See variable `font-lock-keywords'.
470This variable is generally set from `tcl-proc-regexp',
471`tcl-typeword-list', and `tcl-keyword-list' by the function
472`tcl-set-font-lock-keywords'.")
473
474;; FIXME need some way to recognize variables because array refs look
475;; like 2 sexps.
476(defvar tcl-type-alist
477 '(
478 ("expr" tcl-expr)
479 ("catch" tcl-commands)
480 ("if" tcl-expr "then" tcl-commands)
481 ("elseif" tcl-expr "then" tcl-commands)
482 ("elseif" tcl-expr tcl-commands)
483 ("if" tcl-expr tcl-commands)
484 ("while" tcl-expr tcl-commands)
485 ("for" tcl-commands tcl-expr tcl-commands tcl-commands)
486 ("foreach" nil nil tcl-commands)
487 ("for_file" nil nil tcl-commands)
488 ("for_array_keys" nil nil tcl-commands)
489 ("for_recursive_glob" nil nil nil tcl-commands)
490 ;; Loop handling is not perfect, because the third argument can be
491 ;; either a command or an expr, and there is no real way to look
492 ;; forward.
493 ("loop" nil tcl-expr tcl-expr tcl-commands)
494 ("loop" nil tcl-expr tcl-commands)
495 )
496 "Alist that controls indentation.
497\(Actually, this really only controls what happens on continuation lines).
498Each entry looks like `(KEYWORD TYPE ...)'.
499Each type entry describes a sexp after the keyword, and can be one of:
500* nil, meaning that this sexp has no particular type.
501* tcl-expr, meaning that this sexp is an arithmetic expression.
502* tcl-commands, meaning that this sexp holds Tcl commands.
503* a string, which must exactly match the string at the corresponding
504 position for a match to be made.
505
506For example, the entry for the \"loop\" command is:
507
508 (\"loop\" nil tcl-expr tcl-commands)
509
510This means that the \"loop\" command has three arguments. The first
511argument is ignored (for indentation purposes). The second argument
512is a Tcl expression, and the last argument is Tcl commands.")
513
514(defvar tcl-explain-indentation nil
515 "If not `nil', debugging message will be printed during indentation.")
516
517
518
519;;
520;; Work around differences between various versions of Emacs.
521;;
522
523;; We use this because Lemacs 19.9 has what we need.
524(defconst tcl-pps-has-arg-6
525 (or tcl-using-emacs-19
526 (and tcl-using-lemacs-19
527 (condition-case nil
528 (progn
529 (parse-partial-sexp (point) (point) nil nil nil t)
530 t)
531 (error nil))))
532 "t if using an emacs which supports sixth (\"commentstop\") argument
533to parse-partial-sexp.")
534
535;; Its pretty bogus to have to do this, but there is no easier way to
536;; say "match not syntax-1 and not syntax-2". Too bad you can't put
537;; \s in [...]. This sickness is used in Emacs 19 to match a defun
538;; starter. (It is used for this in v18 as well).
539;;(defconst tcl-omit-ws-regexp
540;; (concat "^\\(\\s"
541;; (mapconcat 'char-to-string "w_.()\"\\$'/" "\\|\\s")
542;; "\\)\\S(*")
543;; "Regular expression that matches everything except space, comment
544;;starter, and comment ender syntax codes.")
545
546;; FIXME? Instead of using the hairy regexp above, we just use a
547;; simple one.
548;;(defconst tcl-omit-ws-regexp "^[^] \t\n#}]\\S(*"
549;; "Regular expression used in locating function definitions.")
550
551;; Here's another stab. I think this one actually works. Now the
552;; problem seems to be that there is a bug in Emacs 19.22 where
553;; end-of-defun doesn't really use the brace matching the one that
554;; trails defun-prompt-regexp.
555(defconst tcl-omit-ws-regexp "^[^ \t\n#}][^\n}]+}*[ \t]+")
556
557(defun tcl-internal-beginning-of-defun (&optional arg)
558 "Move backward to next beginning-of-defun.
559With argument, do this that many times.
560Returns t unless search stops due to end of buffer."
561 (interactive "p")
562 (if (or (null arg) (= arg 0))
563 (setq arg 1))
564 (let (success)
565 (while (progn
566 (setq arg (1- arg))
567 (and (>= arg 0)
568 (setq success
569 (re-search-backward tcl-omit-ws-regexp nil 'move 1))))
570 (while (and (looking-at "[]#}]")
571 (setq success
572 (re-search-backward tcl-omit-ws-regexp nil 'move 1)))))
573 (beginning-of-line)
574 (not (null success))))
575
576(defun tcl-internal-end-of-defun (&optional arg)
577 "Move forward to next end of defun.
578An end of a defun is found by moving forward from the beginning of one."
579 (interactive "p")
580 (if (or (null arg) (= arg 0)) (setq arg 1))
581 (let ((start (point)))
582 ;; Was forward-char. I think this works a little better.
583 (forward-line)
584 (tcl-beginning-of-defun)
585 (while (> arg 0)
586 (while (and (re-search-forward tcl-omit-ws-regexp nil 'move 1)
587 (progn (beginning-of-line) t)
588 (looking-at "[]#}]")
589 (progn (forward-line) t)))
590 (let ((next-line (save-excursion
591 (forward-line)
592 (point))))
593 (while (< (point) next-line)
594 (forward-sexp)))
595 (forward-line)
596 (if (> (point) start) (setq arg (1- arg))))))
597
598;; In Emacs 19, we can use begining-of-defun as long as we set up a
599;; certain regexp. In Emacs 18, we need our own function.
600(fset 'tcl-beginning-of-defun
601 (if tcl-using-emacs-19
602 'beginning-of-defun
603 'tcl-internal-beginning-of-defun))
604
605;; Only FSF Emacs 19 works correctly using end-of-defun. Emacs 18 and
606;; Lucid need our own function.
607(fset 'tcl-end-of-defun
608 (if (and tcl-using-emacs-19 (not tcl-using-lemacs-19))
609 'end-of-defun
610 'tcl-internal-end-of-defun))
611
612
613
614;;
615;; Some helper functions.
616;;
617
618(defun tcl-set-proc-regexp ()
619 "Set `tcl-proc-regexp' from variable `tcl-proc-list'."
620 (setq tcl-proc-regexp (concat "^\\("
621 (mapconcat 'identity tcl-proc-list "\\|")
622 "\\)[ \t]+")))
623
624(defun tcl-set-font-lock-keywords ()
625 "Set `tcl-font-lock-keywords'.
626Uses variables `tcl-proc-regexp' and `tcl-keyword-list'."
627 (setq tcl-font-lock-keywords
628 (list
629 ;; Names of functions (and other "defining things").
630 (list (concat tcl-proc-regexp "\\([^ \t\n]+\\)")
631 2 'font-lock-function-name-face)
632
633 ;; Names of type-defining things.
634 (list (concat "\\(\\s-\\|^\\)\\("
635 ;; FIXME Use 'regexp-quote?
636 (mapconcat 'identity tcl-typeword-list "\\|")
637 "\\)\\(\\s-\\|$\\)")
638 2 'font-lock-type-face)
639
640 ;; Keywords. Only recognized if surrounded by whitespace.
641 ;; FIXME consider using "not word or symbol", not
642 ;; "whitespace".
643 (cons (concat "\\(\\s-\\|^\\)\\("
644 ;; FIXME Use regexp-quote?
645 (mapconcat 'identity tcl-keyword-list "\\|")
646 "\\)\\(\\s-\\|$\\)")
647 2)
648 )))
649
650(if tcl-proc-regexp
651 ()
652 (tcl-set-proc-regexp))
653
654(if tcl-font-lock-keywords
655 ()
656 (tcl-set-font-lock-keywords))
657
658
659
660;;
661;; The mode itself.
662;;
663
664(defun tcl-mode ()
665 "Major mode for editing Tcl code.
666Expression and list commands understand all Tcl brackets.
667Tab indents for Tcl code.
668Paragraphs are separated by blank lines only.
669Delete converts tabs to spaces as it moves back.
670
671Variables controlling indentation style:
672 tcl-indent-level
673 Indentation of Tcl statements within surrounding block.
674 tcl-continued-indent-level
675 Indentation of continuation line relative to first line of command.
676
677Variables controlling user interaction with mode (see variable
678documentation for details):
679 tcl-tab-always-indent
680 Controls action of TAB key.
681 tcl-auto-newline
682 Non-nil means automatically newline before and after braces, brackets,
683 and semicolons inserted in Tcl code.
684 tcl-electric-hash-style
685 Controls action of `#' key.
686 tcl-use-hairy-comment-detector
687 If t, use more complicated, but slower, comment detector.
688 This variable is only used in GNU Emacs 19.
689
690Turning on Tcl mode calls the value of the variable `tcl-mode-hook'
691with no args, if that value is non-nil. Read the documentation for
692`tcl-mode-hook' to see what kinds of interesting hook functions
693already exist.
694
695Commands:
696\\{tcl-mode-map}"
697 (interactive)
698 (kill-all-local-variables)
699 (use-local-map tcl-mode-map)
700 (setq major-mode 'tcl-mode)
701 (setq mode-name "Tcl")
702 (setq local-abbrev-table tcl-mode-abbrev-table)
703 (set-syntax-table tcl-mode-syntax-table)
704 (make-local-variable 'paragraph-start)
705 (setq paragraph-start (concat "^$\\|" page-delimiter))
706 (make-local-variable 'paragraph-separate)
707 (setq paragraph-separate paragraph-start)
708 (make-local-variable 'paragraph-ignore-fill-prefix)
709 (setq paragraph-ignore-fill-prefix t)
710 (make-local-variable 'indent-line-function)
711 (setq indent-line-function 'tcl-indent-line)
712 ;; Tcl doesn't require a final newline.
713 ;; (make-local-variable 'require-final-newline)
714 ;; (setq require-final-newline t)
715 (make-local-variable 'comment-start)
716 (setq comment-start "# ")
717 (make-local-variable 'comment-start-skip)
718 (setq comment-start-skip "#+ *")
719 (make-local-variable 'comment-column)
720 (setq comment-column 40)
721 (make-local-variable 'comment-end)
722 (setq comment-end "")
723 (make-local-variable 'font-lock-keywords)
724 (setq font-lock-keywords tcl-font-lock-keywords)
725 (setq imenu-create-index-function 'tcl-imenu-create-index-function)
726 (make-local-variable 'parse-sexp-ignore-comments)
727 (if tcl-using-emacs-19
728 (progn
729 ;; This can only be set to t in Emacs 19 and Lucid Emacs.
730 ;; Emacs 18 and Epoch lose.
731 (setq parse-sexp-ignore-comments t)
732 ;; Lucid Emacs has defun-prompt-regexp, but I don't believe
733 ;; that it works for end-of-defun -- only for
734 ;; beginning-of-defun.
735 (make-local-variable 'defun-prompt-regexp)
736 (setq defun-prompt-regexp tcl-omit-ws-regexp)
737 ;; The following doesn't work in Lucid Emacs 19.6, but maybe
738 ;; it will appear in later versions.
739 (make-local-variable 'add-log-current-defun-function)
740 (setq add-log-current-defun-function 'add-log-tcl-defun))
741 (setq parse-sexp-ignore-comments nil))
742 (run-hooks 'tcl-mode-hook))
743
744
745
746;; This is used for braces, brackets, and semi (except for closing
747;; braces, which are handled specially).
748(defun tcl-electric-char (arg)
749 "Insert character and correct line's indentation."
750 (interactive "p")
751 ;; Indent line first; this looks better if parens blink.
752 (tcl-indent-line)
753 (self-insert-command arg)
754 (if (and tcl-auto-newline (= last-command-char ?\;))
755 (progn
756 (newline)
757 (tcl-indent-line))))
758
759;; This is used for closing braces. If tcl-auto-newline is set, can
760;; insert a newline both before and after the brace, depending on
761;; context. FIXME should this be configurable? Does anyone use this?
762(defun tcl-electric-brace (arg)
763 "Insert character and correct line's indentation."
764 (interactive "p")
765 ;; If auto-newlining and there is stuff on the same line, insert a
766 ;; newline first.
767 (if tcl-auto-newline
768 (progn
769 (if (save-excursion
770 (skip-chars-backward " \t")
771 (bolp))
772 ()
773 (tcl-indent-line)
774 (newline))
775 ;; In auto-newline case, must insert a newline after each
776 ;; brace. So an explicit loop is needed.
777 (while (> arg 0)
778 (insert last-command-char)
779 (tcl-indent-line)
780 (newline)
781 (setq arg (1- arg))))
782 (self-insert-command arg))
783 (tcl-indent-line))
784
785
786
787(defun tcl-indent-command (&optional arg)
788 "Indent current line as Tcl code, or in some cases insert a tab character.
789If tcl-tab-always-indent is t (the default), always indent current line.
790If tcl-tab-always-indent is nil and point is not in the indentation
791area at the beginning of the line, a TAB is inserted.
792Other values of tcl-tab-always-indent cause the first possible action
793from the following list to take place:
794
795 1. Move from beginning of line to correct indentation.
796 2. Delete an empty comment.
797 3. Move forward to start of comment, indenting if necessary.
798 4. Move forward to end of line, indenting if necessary.
799 5. Create an empty comment.
800 6. Move backward to start of comment, indenting if necessary."
801 (interactive "p")
802 (cond
803 ((not tcl-tab-always-indent)
804 ;; Indent if in identation area, otherwise insert TAB.
805 (if (<= (current-column) (current-indentation))
806 (tcl-indent-line)
807 (self-insert-command arg)))
808 ((eq tcl-tab-always-indent t)
809 ;; Always indent.
810 (tcl-indent-line))
811 (t
812 ;; "Perl-mode" style TAB command.
813 (let* ((ipoint (point))
814 (eolpoint (progn
815 (end-of-line)
816 (point)))
817 (comment-p (tcl-in-comment)))
818 (cond
819 ((= ipoint (save-excursion
820 (beginning-of-line)
821 (point)))
822 (beginning-of-line)
823 (tcl-indent-line)
824 ;; If indenting didn't leave us in column 0, go to the
825 ;; indentation. Otherwise leave point at end of line. This
826 ;; is a hack.
827 (if (= (point) (save-excursion
828 (beginning-of-line)
829 (point)))
830 (end-of-line)
831 (back-to-indentation)))
832 ((and comment-p (looking-at "[ \t]*$"))
833 ;; Empty comment, so delete it. We also delete any ";"
834 ;; characters at the end of the line. I think this is
835 ;; friendlier, but I don't know how other people will feel.
836 (backward-char)
837 (skip-chars-backward " \t;")
838 (delete-region (point) eolpoint))
839 ((and comment-p (< ipoint (point)))
840 ;; Before comment, so skip to it.
841 (tcl-indent-line)
842 (indent-for-comment))
843 ((/= ipoint eolpoint)
844 ;; Go to end of line (since we're not there yet).
845 (goto-char eolpoint)
846 (tcl-indent-line))
847 ((not comment-p)
848 ;; Create an empty comment (since there isn't one on this
849 ;; line). If line is not blank, make sure we insert a ";"
850 ;; first.
851 (beginning-of-line)
852 (if (/= (point) eolpoint)
853 (progn
854 (goto-char eolpoint)
855 (or (tcl-real-command-p)
856 (insert ";"))))
857 (tcl-indent-line)
858 (indent-for-comment))
859 (t
860 ;; Go to start of comment. We don't leave point where it is
861 ;; because we want to skip comment-start-skip.
862 (tcl-indent-line)
863 (indent-for-comment)))))))
864
865(defun tcl-indent-line ()
866 "Indent current line as Tcl code.
867Return the amount the indentation changed by."
868 (let ((indent (calculate-tcl-indent nil))
869 beg shift-amt
870 (case-fold-search nil)
871 (pos (- (point-max) (point))))
872 (beginning-of-line)
873 (setq beg (point))
874 (cond ((eq indent nil)
875 (setq indent (current-indentation)))
876 (t
877 (skip-chars-forward " \t")
878 (if (listp indent) (setq indent (car indent)))
879 (cond ((= (following-char) ?})
880 (setq indent (- indent tcl-indent-level)))
881 ((= (following-char) ?\])
882 (setq indent (- indent 1))))))
883 (skip-chars-forward " \t")
884 (setq shift-amt (- indent (current-column)))
885 (if (zerop shift-amt)
886 (if (> (- (point-max) pos) (point))
887 (goto-char (- (point-max) pos)))
888 (delete-region beg (point))
889 (indent-to indent)
890 ;; If initial point was within line's indentation,
891 ;; position after the indentation. Else stay at same point in text.
892 (if (> (- (point-max) pos) (point))
893 (goto-char (- (point-max) pos))))
894 shift-amt))
895
896(defun tcl-figure-type ()
897 "Determine type of sexp at point.
898This is either 'tcl-expr, 'tcl-commands, or nil. Puts point at start
899of sexp that indicates types.
900
901See documentation for variable `tcl-type-alist' for more information."
902 (let ((count 0)
903 result
904 word-stack)
905 (while (and (< count 5)
906 (not result))
907 (condition-case nil
908 (progn
909 ;; FIXME should use "tcl-backward-sexp", which would skip
910 ;; over entire variables, etc.
911 (backward-sexp)
912 (if (looking-at "[a-zA-Z_]+")
913 (let ((list tcl-type-alist)
914 entry)
915 (setq word-stack (cons (current-word) word-stack))
916 (while (and list (not result))
917 (setq entry (car list))
918 (setq list (cdr list))
919 (let ((index 0))
920 (while (and entry (<= index count))
921 ;; Abort loop if string does not match word on
922 ;; stack.
923 (and (stringp (car entry))
924 (not (string= (car entry)
925 (nth index word-stack)))
926 (setq entry nil))
927 (setq entry (cdr entry))
928 (setq index (1+ index)))
929 (and (> index count)
930 (not (stringp (car entry)))
931 (setq result (car entry)))
932 )))
933 (setq word-stack (cons nil word-stack))))
934 (error nil))
935 (setq count (1+ count)))
936 (and tcl-explain-indentation
937 (message "Indentation type %s" result))
938 result))
939
940(defun calculate-tcl-indent (&optional parse-start)
941 "Return appropriate indentation for current line as Tcl code.
942In usual case returns an integer: the column to indent to.
943Returns nil if line starts inside a string, t if in a comment."
944 (save-excursion
945 (beginning-of-line)
946 (let* ((indent-point (point))
947 (case-fold-search nil)
948 (continued-line
949 (save-excursion
950 (if (bobp)
951 nil
952 (backward-char)
953 (= ?\\ (preceding-char)))))
954 (continued-indent-value (if continued-line
955 tcl-continued-indent-level
956 0))
957 state
958 containing-sexp
959 found-next-line)
960 (if parse-start
961 (goto-char parse-start)
962 (tcl-beginning-of-defun))
963 (while (< (point) indent-point)
964 (setq parse-start (point))
965 (setq state (parse-partial-sexp (point) indent-point 0))
966 (setq containing-sexp (car (cdr state))))
967 (cond ((or (nth 3 state) (nth 4 state))
968 ;; Inside comment or string. Return nil or t if should
969 ;; not change this line
970 (nth 4 state))
971 ((null containing-sexp)
972 ;; Line is at top level.
973 continued-indent-value)
974 (t
975 ;; Set expr-p if we are looking at the expression part of
976 ;; an "if", "expr", etc statement. Set commands-p if we
977 ;; are looking at the body part of an if, while, etc
978 ;; statement. FIXME Should check for "for" loops here.
979 (goto-char containing-sexp)
980 (let* ((sexpr-type (tcl-figure-type))
981 (expr-p (eq sexpr-type 'tcl-expr))
982 (commands-p (eq sexpr-type 'tcl-commands))
983 (expr-start (point)))
984 ;; Find the first statement in the block and indent
985 ;; like it. The first statement in the block might be
986 ;; on the same line, so what we do is skip all
987 ;; "virtually blank" lines, looking for a non-blank
988 ;; one. A line is virtually blank if it only contains
989 ;; a comment and whitespace. FIXME continued comments
990 ;; aren't supported. They are a wart on Tcl anyway.
991 ;; We do it this funky way because we want to know if
992 ;; we've found a statement on some line _after_ the
993 ;; line holding the sexp opener.
994 (goto-char containing-sexp)
995 (forward-char)
996 (if (and (< (point) indent-point)
997 (looking-at "[ \t]*\\(#.*\\)?$"))
998 (progn
999 (forward-line)
1000 (while (and (< (point) indent-point)
1001 (looking-at "[ \t]*\\(#.*\\)?$"))
1002 (setq found-next-line t)
1003 (forward-line))))
1004 (if (or continued-line
1005 (/= (char-after containing-sexp) ?{)
1006 expr-p)
1007 (progn
1008 ;; Line is continuation line, or the sexp opener
1009 ;; is not a curly brace, or we are are looking at
1010 ;; an `expr' expression (which must be split
1011 ;; specially). So indentation is column of first
1012 ;; good spot after sexp opener (with some added
1013 ;; in the continued-line case). If there is no
1014 ;; nonempty line before the indentation point, we
1015 ;; use the column of the character after the sexp
1016 ;; opener.
1017 (if (>= (point) indent-point)
1018 (progn
1019 (goto-char containing-sexp)
1020 (forward-char))
1021 (skip-chars-forward " \t"))
1022 (+ (current-column) continued-indent-value))
1023 ;; After a curly brace, and not a continuation line.
1024 ;; So take indentation from first good line after
1025 ;; start of block, unless that line is on the same
1026 ;; line as the opening brace. In this case use the
1027 ;; indentation of the opening brace's line, plus
1028 ;; another indent step. If we are in the body part
1029 ;; of an "if" or "while" then the indentation is
1030 ;; taken from the line holding the start of the
1031 ;; statement.
1032 (if (and (< (point) indent-point)
1033 found-next-line)
1034 (current-indentation)
1035 (if commands-p
1036 (goto-char expr-start)
1037 (goto-char containing-sexp))
1038 (+ (current-indentation) tcl-indent-level)))))))))
1039
1040
1041
1042(defun mark-tcl-function ()
1043 "Put mark at end of Tcl function, point at beginning."
1044 (interactive)
1045 (push-mark (point))
1046 (tcl-end-of-defun)
1047 (if tcl-using-emacs-19
1048 (push-mark (point) nil t)
1049 (push-mark (point)))
1050 (tcl-beginning-of-defun)
1051 (backward-paragraph))
1052
1053
1054
1055(defun indent-tcl-exp ()
1056 "Indent each line of the Tcl grouping following point."
1057 (interactive)
1058 (let ((indent-stack (list nil))
1059 (contain-stack (list (point)))
1060 (case-fold-search nil)
1061 outer-loop-done inner-loop-done state ostate
1062 this-indent last-sexp continued-line
1063 (next-depth 0)
1064 last-depth)
1065 (save-excursion
1066 (forward-sexp 1))
1067 (save-excursion
1068 (setq outer-loop-done nil)
1069 (while (and (not (eobp)) (not outer-loop-done))
1070 (setq last-depth next-depth)
1071 ;; Compute how depth changes over this line
1072 ;; plus enough other lines to get to one that
1073 ;; does not end inside a comment or string.
1074 ;; Meanwhile, do appropriate indentation on comment lines.
1075 (setq inner-loop-done nil)
1076 (while (and (not inner-loop-done)
1077 (not (and (eobp) (setq outer-loop-done t))))
1078 (setq ostate state)
1079 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
1080 nil nil state))
1081 (setq next-depth (car state))
1082 (if (and (car (cdr (cdr state)))
1083 (>= (car (cdr (cdr state))) 0))
1084 (setq last-sexp (car (cdr (cdr state)))))
1085 (if (or (nth 4 ostate))
1086 (tcl-indent-line))
1087 (if (or (nth 3 state))
1088 (forward-line 1)
1089 (setq inner-loop-done t)))
1090 (if (<= next-depth 0)
1091 (setq outer-loop-done t))
1092 (if outer-loop-done
1093 nil
1094 ;; If this line had ..))) (((.. in it, pop out of the levels
1095 ;; that ended anywhere in this line, even if the final depth
1096 ;; doesn't indicate that they ended.
1097 (while (> last-depth (nth 6 state))
1098 (setq indent-stack (cdr indent-stack)
1099 contain-stack (cdr contain-stack)
1100 last-depth (1- last-depth)))
1101 (if (/= last-depth next-depth)
1102 (setq last-sexp nil))
1103 ;; Add levels for any parens that were started in this line.
1104 (while (< last-depth next-depth)
1105 (setq indent-stack (cons nil indent-stack)
1106 contain-stack (cons nil contain-stack)
1107 last-depth (1+ last-depth)))
1108 (if (null (car contain-stack))
1109 (setcar contain-stack
1110 (or (car (cdr state))
1111 (save-excursion
1112 (forward-sexp -1)
1113 (point)))))
1114 (forward-line 1)
1115 (setq continued-line
1116 (save-excursion
1117 (backward-char)
1118 (= (preceding-char) ?\\)))
1119 (skip-chars-forward " \t")
1120 (if (eolp)
1121 nil
1122 (if (and (car indent-stack)
1123 (>= (car indent-stack) 0))
1124 ;; Line is on an existing nesting level.
1125 (setq this-indent (car indent-stack))
1126 ;; Just started a new nesting level.
1127 ;; Compute the standard indent for this level.
1128 (let ((val (calculate-tcl-indent
1129 (if (car indent-stack)
1130 (- (car indent-stack))))))
1131 (setcar indent-stack
1132 (setq this-indent val))
1133 (setq continued-line nil)))
1134 (cond ((not (numberp this-indent)))
1135 ((= (following-char) ?})
1136 (setq this-indent (- this-indent tcl-indent-level)))
1137 ((= (following-char) ?\])
1138 (setq this-indent (- this-indent 1))))
1139 ;; Put chosen indentation into effect.
1140 (or (null this-indent)
1141 (= (current-column)
1142 (if continued-line
1143 (+ this-indent tcl-indent-level)
1144 this-indent))
1145 (progn
1146 (delete-region (point) (progn (beginning-of-line) (point)))
1147 (indent-to
1148 (if continued-line
1149 (+ this-indent tcl-indent-level)
1150 this-indent)))))))))
1151 )
1152
1153
1154
1155;;
1156;; Interfaces to other packages.
1157;;
1158
1159(defun tcl-imenu-create-index-function ()
1160 "Generate alist of indices for imenu."
1161 (let ((re (concat tcl-proc-regexp "\\([^ \t\n{]+\\)"))
1162 alist)
1163 (imenu-progress-message 0)
1164 (goto-char (point-min))
1165 (while (re-search-forward re nil t)
1166 (imenu-progress-message nil)
1167 ;; Position on start of proc name, not beginning of line.
1168 (setq alist (cons
1169 (cons (buffer-substring (match-beginning 2) (match-end 2))
1170 (match-beginning 2))
1171 alist)))
1172 (imenu-progress-message 100)
1173 (nreverse alist)))
1174
1175;; FIXME Definition of function is very ad-hoc. Should use
1176;; tcl-beginning-of-defun. Also has incestuous knowledge about the
1177;; format of tcl-proc-regexp.
1178(defun add-log-tcl-defun ()
1179 "Return name of Tcl function point is in, or nil."
1180 (save-excursion
1181 (if (re-search-backward
1182 (concat tcl-proc-regexp "\\([^ \t\n{]+\\)") nil t)
1183 (buffer-substring (match-beginning 2)
1184 (match-end 2)))))
1185
1186
1187
1188;;
1189;; Helper functions for inferior Tcl mode.
1190;;
1191
1192;; This exists to let us delete the prompt when commands are sent
1193;; directly to the inferior Tcl. See gud.el for an explanation of how
1194;; it all works (I took it from there). This stuff doesn't really
1195;; work as well as I'd like it to. But I don't believe there is
1196;; anything useful that can be done.
1197(defvar inferior-tcl-delete-prompt-marker nil)
1198
1199(defun tcl-filter (proc string)
1200 (let ((inhibit-quit t))
1201 (save-excursion
1202 (set-buffer (process-buffer proc))
1203 (goto-char (process-mark proc))
1204 ;; Delete prompt if requested.
1205 (if (marker-buffer inferior-tcl-delete-prompt-marker)
1206 (progn
1207 (delete-region (point) inferior-tcl-delete-prompt-marker)
1208 (set-marker inferior-tcl-delete-prompt-marker nil)))))
1209 (comint-output-filter proc string))
1210
1211(defun tcl-send-string (proc string)
1212 (save-excursion
1213 (set-buffer (process-buffer proc))
1214 (goto-char (process-mark proc))
1215 (beginning-of-line)
1216 (if (looking-at comint-prompt-regexp)
1217 (set-marker inferior-tcl-delete-prompt-marker (point))))
1218 (comint-send-string proc string))
1219
1220(defun tcl-send-region (proc start end)
1221 (save-excursion
1222 (set-buffer (process-buffer proc))
1223 (goto-char (process-mark proc))
1224 (beginning-of-line)
1225 (if (looking-at comint-prompt-regexp)
1226 (set-marker inferior-tcl-delete-prompt-marker (point))))
1227 (comint-send-region proc start end))
1228
1229(defun switch-to-tcl (eob-p)
1230 "Switch to inferior Tcl process buffer.
1231With argument, positions cursor at end of buffer."
1232 (interactive "P")
1233 (if (get-buffer inferior-tcl-buffer)
1234 (pop-to-buffer inferior-tcl-buffer)
1235 (error "No current inferior Tcl buffer"))
1236 (cond (eob-p
1237 (push-mark)
1238 (goto-char (point-max)))))
1239
1240(defun inferior-tcl-proc ()
1241 "Return current inferior Tcl process.
1242See variable `inferior-tcl-buffer'."
1243 (let ((proc (get-buffer-process (if (eq major-mode 'inferior-tcl-mode)
1244 (current-buffer)
1245 inferior-tcl-buffer))))
1246 (or proc
1247 (error "No Tcl process; see variable `inferior-tcl-buffer'"))))
1248
1249(defun tcl-eval-region (start end &optional and-go)
1250 "Send the current region to the inferior Tcl process.
1251Prefix argument means switch to the Tcl buffer afterwards."
1252 (interactive "r\nP")
1253 (let ((proc (inferior-tcl-proc)))
1254 (tcl-send-region proc start end)
1255 (tcl-send-string proc "\n")
1256 (if and-go (switch-to-tcl t))))
1257
1258(defun tcl-eval-defun (&optional and-go)
1259 "Send the current defun to the inferior Tcl process.
1260Prefix argument means switch to the Tcl buffer afterwards."
1261 (interactive "P")
1262 (save-excursion
1263 (tcl-end-of-defun)
1264 (let ((end (point)))
1265 (tcl-beginning-of-defun)
1266 (tcl-eval-region (point) end)))
1267 (if and-go (switch-to-tcl t)))
1268
1269
1270
1271;;
1272;; Inferior Tcl mode itself.
1273;;
1274
1275(defun inferior-tcl-mode ()
1276 "Major mode for interacting with Tcl interpreter.
1277
1278A Tcl process can be started with M-x inferior-tcl.
1279
1280Entry to this mode runs the hooks comint-mode-hook and
1281inferior-tcl-mode-hook, in that order.
1282
1283You can send text to the inferior Tcl process from other buffers
1284containing Tcl source.
1285
1286Variables controlling Inferior Tcl mode:
1287 tcl-application
1288 Name of program to run.
1289 tcl-command-switches
1290 Command line arguments to `tcl-application'.
1291 tcl-prompt-regexp
1292 Matches prompt.
1293 inferior-tcl-source-command
1294 Command to use to read Tcl file in running application.
1295 inferior-tcl-buffer
1296 The current inferior Tcl process buffer. See variable
1297 documentation for details on multiple-process support.
1298
1299The following commands are available:
1300\\{inferior-tcl-mode-map}"
1301 (interactive)
1302 (comint-mode)
1303 (setq comint-prompt-regexp (or tcl-prompt-regexp
1304 (concat "^"
1305 (regexp-quote tcl-application)
1306 ">")))
1307 (setq major-mode 'inferior-tcl-mode)
1308 (setq mode-name "Inferior Tcl")
1309 (setq mode-line-process '(": %s"))
1310 (use-local-map inferior-tcl-mode-map)
1311 (setq local-abbrev-table tcl-mode-abbrev-table)
1312 (set-syntax-table tcl-mode-syntax-table)
1313 (if tcl-using-emacs-19
1314 (progn
1315 (make-local-variable 'defun-prompt-regexp)
1316 (setq defun-prompt-regexp tcl-omit-ws-regexp)))
1317 (make-local-variable 'inferior-tcl-delete-prompt-marker)
1318 (setq inferior-tcl-delete-prompt-marker (make-marker))
1319 (set-process-filter (get-buffer-process (current-buffer)) 'tcl-filter)
1320 (run-hooks 'inferior-tcl-mode-hook))
1321
1322(defun inferior-tcl (cmd)
1323 "Run inferior Tcl process.
1324Prefix arg means enter program name interactively.
1325See documentation for function `inferior-tcl-mode' for more information."
1326 (interactive
1327 (list (if current-prefix-arg
1328 (read-string "Run Tcl: " tcl-application)
1329 tcl-application)))
1330 (if (not (comint-check-proc "*inferior-tcl*"))
1331 (progn
1332 (set-buffer (apply (function make-comint) "inferior-tcl" cmd nil
1333 tcl-command-switches))
1334 (inferior-tcl-mode)))
1335 (make-local-variable 'tcl-application)
1336 (setq tcl-application cmd)
1337 (setq inferior-tcl-buffer "*inferior-tcl*")
1338 (switch-to-buffer "*inferior-tcl*"))
1339
1340(and (fboundp 'defalias)
1341 (defalias 'run-tcl 'inferior-tcl))
1342
1343
1344
1345;;
1346;; Auto-fill support.
1347;;
1348
1349(defun tcl-real-command-p ()
1350 "Return nil if point is not at the beginning of a command.
1351A command is the first word on an otherwise empty line, or the
1352first word following a semicolon, opening brace, or opening bracket."
1353 (save-excursion
1354 (skip-chars-backward " \t")
1355 (cond
1356 ((bobp) t)
1357 ((bolp)
1358 (backward-char)
1359 ;; Note -- continued comments are not supported here. I
1360 ;; consider those to be a wart on the language.
1361 (not (eq ?\\ (preceding-char))))
1362 (t
1363 (memq (preceding-char) '(?\; ?{ ?\[))))))
1364
1365;; FIXME doesn't actually return t. See last case.
1366(defun tcl-real-comment-p ()
1367 "Return t if point is just after the `#' beginning a real comment.
1368Does not check to see if previous char is actually `#'.
1369A real comment is either at the beginning of the buffer,
1370preceeded only by whitespace on the line, or has a preceeding
1371semicolon, opening brace, or opening bracket on the same line."
1372 (save-excursion
1373 (backward-char)
1374 (tcl-real-command-p)))
1375
1376(defun tcl-hairy-scan-for-comment (state end always-stop)
1377 "Determine if point is in a comment.
1378Returns a list of the form `(FLAG . STATE)'. STATE can be used
1379as input to future invocations. FLAG is nil if not in comment,
1380t otherwise. If in comment, leaves point at beginning of comment.
1381Only works in Emacs 19. See also `tcl-simple-scan-for-comment', a
1382simpler version that is often right, and works in Emacs 18."
1383 (let ((bol (save-excursion
1384 (goto-char end)
1385 (beginning-of-line)
1386 (point)))
1387 real-comment
1388 last-cstart)
1389 (while (and (not last-cstart) (< (point) end))
1390 (setq real-comment nil) ;In case we've looped around and it is
1391 ;set.
1392 (setq state (parse-partial-sexp (point) end nil nil state t))
1393 (if (nth 4 state)
1394 (progn
1395 ;; If ALWAYS-STOP is set, stop even if we don't have a
1396 ;; real comment, or if the comment isn't on the same line
1397 ;; as the end.
1398 (if always-stop (setq last-cstart (point)))
1399 ;; If we have a real comment, then set the comment
1400 ;; starting point if we are on the same line as the ending
1401 ;; location.
1402 (setq real-comment (tcl-real-comment-p))
1403 (if real-comment
1404 (progn
1405 (and (> (point) bol) (setq last-cstart (point)))
1406 ;; NOTE Emacs 19 has a misfeature whereby calling
1407 ;; parse-partial-sexp with COMMENTSTOP set and with
1408 ;; an initial list that says point is in a comment
1409 ;; will cause an immediate return. So we must skip
1410 ;; over the comment ourselves.
1411 (beginning-of-line 2)))
1412 ;; Frob the state to make it look like we aren't in a
1413 ;; comment.
1414 (setcar (nthcdr 4 state) nil))))
1415 (and last-cstart
1416 (goto-char last-cstart))
1417 (cons real-comment state)))
1418
1419(defun tcl-hairy-in-comment ()
1420 "Return t if point is in a comment, and leave point at beginning
1421of comment."
1422 (let ((save (point)))
1423 (tcl-beginning-of-defun)
1424 (car (tcl-hairy-scan-for-comment nil save nil))))
1425
1426(defun tcl-simple-in-comment ()
1427 "Return t if point is in comment, and leave point at beginning
1428of comment. This is faster that `tcl-hairy-in-comment', but is
1429correct less often."
1430 (let ((save (point))
1431 comment)
1432 (beginning-of-line)
1433 (while (and (< (point) save) (not comment))
1434 (search-forward "#" save 'move)
1435 (setq comment (tcl-real-comment-p)))
1436 comment))
1437
1438(defun tcl-in-comment ()
1439 "Return t if point is in comment, and leave point at beginning
1440of comment."
1441 (if (and tcl-pps-has-arg-6
1442 tcl-use-hairy-comment-detector)
1443 (tcl-hairy-in-comment)
1444 (tcl-simple-in-comment)))
1445
1446(defun tcl-do-auto-fill ()
1447 "Auto-fill function for Tcl mode. Only auto-fills in a comment."
1448 (let (in-comment
1449 col)
1450 (save-excursion
1451 (setq in-comment (tcl-in-comment))
1452 (if in-comment
1453 (setq col (1- (current-column)))))
1454 (if in-comment
1455 (progn
1456 (do-auto-fill)
1457 (save-excursion
1458 (back-to-indentation)
1459 (delete-region (point) (save-excursion
1460 (beginning-of-line)
1461 (point)))
1462 (indent-to-column col))))))
1463
1464
1465
1466;;
1467;; Help-related code.
1468;;
1469
1470(defvar tcl-help-saved-dir nil
1471 "Saved help directory. If `tcl-help-directory' changes, this allows
1472tcl-help-on-word to update the alist")
1473
1474(defvar tcl-help-alist nil
1475 "Alist with command names as keys and filenames as values.")
1476
1477(defun tcl-help-snarf-commands (dir)
1478 "Build alist of commands and filenames. There is probably a much
1479better implementation of this, but I'm too tired to think of it right
1480now."
1481 (let ((files (directory-files dir t)))
1482 (while files
1483 (if (and (file-directory-p (car files))
1484 (not
1485 (let ((fpart (file-name-nondirectory (car files))))
1486 (or (equal fpart ".")
1487 (equal fpart "..")))))
1488 (let ((matches (directory-files (car files) t)))
1489 (while matches
1490 (or (file-directory-p (car matches))
1491 (setq tcl-help-alist
1492 (cons
1493 (cons (file-name-nondirectory (car matches))
1494 (car matches))
1495 tcl-help-alist)))
1496 (setq matches (cdr matches)))))
1497 (setq files (cdr files)))))
1498
1499(defun tcl-reread-help-files ()
1500 "Set up to re-read files, and then do it."
1501 (interactive)
1502 (message "Building Tcl help file index...")
1503 (setq tcl-help-saved-dir tcl-help-directory)
1504 (setq tcl-help-alist nil)
1505 (tcl-help-snarf-commands tcl-help-directory)
1506 (message "Building Tcl help file index...done"))
1507
1508(defun tcl-current-word (flag)
1509 "Return current command word, or nil.
1510If FLAG is nil, just uses `current-word'.
1511Otherwise scans backward for most likely Tcl command word."
1512 (if (and flag (eq major-mode 'tcl-mode))
1513 (condition-case nil
1514 (save-excursion
1515 ;; Look backward for first word actually in alist.
1516 (if (bobp)
1517 ()
1518 (while (and (not (bobp))
1519 (not (tcl-real-command-p)))
1520 (backward-sexp)))
1521 (if (assoc (current-word) tcl-help-alist)
1522 (current-word)))
1523 (error nil))
1524 (current-word)))
1525
1526(defun tcl-help-on-word (command &optional arg)
1527 "Get help on Tcl command. Default is word at point.
1528Prefix argument means invert sense of `tcl-use-smart-word-finder'."
1529 (interactive
1530 (list
1531 (progn
1532 (if (not (string= tcl-help-directory tcl-help-saved-dir))
1533 (tcl-reread-help-files))
1534 (let ((word (tcl-current-word
1535 (if current-prefix-arg
1536 (not tcl-use-smart-word-finder)
1537 tcl-use-smart-word-finder))))
1538 (completing-read
1539 (if (or (null word) (string= word ""))
1540 "Help on Tcl command: "
1541 (format "Help on Tcl command (default %s): " word))
1542 tcl-help-alist nil t)))
1543 current-prefix-arg))
1544 (if (not (string= tcl-help-directory tcl-help-saved-dir))
1545 (tcl-reread-help-files))
1546 (if (string= command "")
1547 (setq command (tcl-current-word
1548 (if arg
1549 (not tcl-use-smart-word-finder)
1550 tcl-use-smart-word-finder))))
1551 (let* ((help (get-buffer-create "*Tcl help*"))
1552 (cell (assoc command tcl-help-alist))
1553 (file (and cell (cdr cell))))
1554 (set-buffer help)
1555 (delete-region (point-min) (point-max))
1556 (if file
1557 (progn
1558 (insert "*** " command "\n\n")
1559 (insert-file-contents file))
1560 (if (string= command "")
1561 (insert "Magical Pig!")
1562 (insert "Tcl command " command " not in help\n")))
1563 (set-buffer-modified-p nil)
1564 (goto-char (point-min))
1565 (display-buffer help)))
1566
1567
1568
1569;;
1570;; Other interactive stuff.
1571;;
1572
1573(defvar tcl-previous-dir/file nil
1574 "Record last directory and file used in loading.
1575This holds a cons cell of the form `(DIRECTORY . FILE)'
1576describing the last `tcl-load-file' command.")
1577
1578(defun tcl-load-file (file &optional and-go)
1579 "Load a Tcl file into the inferior Tcl process.
1580Prefix argument means switch to the Tcl buffer afterwards."
1581 (interactive
1582 (list
1583 ;; car because comint-get-source returns a list holding the
1584 ;; filename.
1585 (car (comint-get-source "Load Tcl file: " tcl-previous-dir/file
1586 '(tcl-mode) t))
1587 current-prefix-arg))
1588 (comint-check-source file)
1589 (setq tcl-previous-dir/file (cons (file-name-directory file)
1590 (file-name-nondirectory file)))
1591 (tcl-send-string (inferior-tcl-proc)
1592 (format inferior-tcl-source-command (tcl-quote file)))
1593 (if and-go (switch-to-tcl t)))
1594
1595;; Maybe this should work just like tcl-load-file. But I think what
1596;; I've implemented will turn out to be more useful.
1597(defun tcl-restart-with-file (file &optional and-go)
1598 "Restart inferior Tcl with file.
1599If an inferior Tcl process exists, it is killed first.
1600Prefix argument means switch to the Tcl buffer afterwards."
1601 (interactive
1602 (list
1603 (car (comint-get-source "Restart with Tcl file: "
1604 (or (and
1605 (eq major-mode 'tcl-mode)
1606 (buffer-file-name))
1607 tcl-previous-dir/file)
1608 '(tcl-mode) t))
1609 current-prefix-arg))
1610 (let* ((buf (if (eq major-mode 'inferior-tcl-mode)
1611 (current-buffer)
1612 inferior-tcl-buffer))
1613 (proc (and buf (get-process buf))))
1614 (cond
1615 ((not (and buf (get-buffer buf)))
1616 ;; I think this will be ok.
1617 (inferior-tcl tcl-application)
1618 (tcl-load-file file and-go))
1619 ((or
1620 (not (comint-check-proc buf))
1621 (yes-or-no-p
1622 "A Tcl process is running, are you sure you want to reset it? "))
1623 (save-excursion
1624 (comint-check-source file)
1625 (setq tcl-previous-dir/file (cons (file-name-directory file)
1626 (file-name-nondirectory file)))
1627 (comint-exec (get-buffer-create buf)
1628 (if proc
1629 (process-name proc)
1630 "inferior-tcl")
1631 tcl-application file tcl-command-switches)
1632 (if and-go (switch-to-tcl t)))))))
1633
1634;; FIXME I imagine you can do this under Emacs 18. I just don't know
1635;; how.
1636(defun tcl-auto-fill-mode (&optional arg)
1637 "Like `auto-fill-mode', but controls filling of Tcl comments."
1638 (interactive "P")
1639 (and (not tcl-using-emacs-19)
1640 (error "You must use Emacs 19 to get this feature."))
1641 ;; Following code taken from "auto-fill-mode" (simple.el).
1642 (prog1
1643 (setq auto-fill-function
1644 (if (if (null arg)
1645 (not auto-fill-function)
1646 (> (prefix-numeric-value arg) 0))
1647 'tcl-do-auto-fill
1648 nil))
1649 ;; Update mode line. FIXME I'd use force-mode-line-update, but I
1650 ;; don't know if it exists in v18.
1651 (set-buffer-modified-p (buffer-modified-p))))
1652
1653(defun tcl-electric-hash (&optional count)
1654 "Insert a `#' and quote if it does not start a real comment.
1655Prefix arg is number of `#'s to insert.
1656See variable `tcl-electric-hash-style' for description of quoting
1657styles."
1658 (interactive "p")
1659 (or count (setq count 1))
1660 (if (> count 0)
1661 (let ((type
1662 (if (eq tcl-electric-hash-style 'smart)
1663 (if (> count 3) ; FIXME what is "smart"?
1664 'quote
1665 'backslash)
1666 tcl-electric-hash-style))
1667 comment)
1668 (if type
1669 (progn
1670 (save-excursion
1671 (insert "#")
1672 (setq comment (tcl-in-comment)))
1673 (delete-char 1)
1674 (and tcl-explain-indentation (message "comment: %s" comment))
1675 (cond
1676 ((eq type 'quote)
1677 (if (not comment)
1678 (insert "\"")))
1679 ((eq type 'backslash)
1680 ;; The following will set count to 0, so the
1681 ;; insert-char can still be run.
1682 (if (not comment)
1683 (while (> count 0)
1684 (insert "\\#")
1685 (setq count (1- count)))))
1686 (t nil))))
1687 (insert-char ?# count))))
1688
1689(defun tcl-hashify-buffer ()
1690 "Quote all `#'s in current buffer that aren't Tcl comments."
1691 (interactive)
1692 (save-excursion
1693 (goto-char (point-min))
1694 (if (and tcl-pps-has-arg-6 tcl-use-hairy-comment-detector)
1695 (let (state
1696 result)
1697 (while (< (point) (point-max))
1698 (setq result (tcl-hairy-scan-for-comment state (point-max) t))
1699 (if (car result)
1700 (beginning-of-line 2)
1701 (backward-char)
1702 (if (eq ?# (following-char))
1703 (insert "\\"))
1704 (forward-char))
1705 (setq state (cdr result))))
1706 (while (and (< (point) (point-max))
1707 (search-forward "#" nil 'move))
1708 (if (tcl-real-comment-p)
1709 (beginning-of-line 2)
1710 ;; There's really no good way for the simple converter to
1711 ;; work. So we just quote # if it isn't already quoted.
1712 ;; Bogus, but it works.
1713 (backward-char)
1714 (if (not (eq ?\\ (preceding-char)))
1715 (insert "\\"))
1716 (forward-char))))))
1717
1718;; The following was inspired by the Tcl editing mode written by
1719;; Gregor Schmid <schmid@fb3-s7.math.TU-Berlin.DE>. His version also
1720;; attempts to snarf the command line options from the command line,
1721;; but I didn't think that would really be that helpful (doesn't seem
1722;; like it owould be right enough. His version also looks for the
1723;; "#!/bin/csh ... exec" hack, but that seemed even less useful.
1724(defun tcl-guess-application ()
1725 "Attempt to guess Tcl application by looking at first line.
1726The first line is assumed to look like \"#!.../program ...\"."
1727 (save-excursion
1728 (goto-char (point-min))
1729 (if (looking-at "#![^ \t]*/\\([^ \t/]+\\)\\([ \t]\\|$\\)")
1730 (progn
1731 (make-local-variable 'tcl-application)
1732 (setq tcl-application (buffer-substring (match-beginning 1)
1733 (match-end 1)))))))
1734
1735;; This only exists to put on the menubar. I couldn't figure out any
1736;; other way to do it. FIXME should take "number of #-marks"
1737;; argument.
1738(defun tcl-uncomment-region (beg end)
1739 "Uncomment region."
1740 (interactive "r")
1741 (comment-region beg end -1))
1742
1743
1744
1745;;
1746;; Lucid menu support.
1747;; Taken from schmid@fb3-s7.math.TU-Berlin.DE (Gregor Schmid),
1748;; who wrote a different Tcl mode.
1749;; We also have simple support for menus in FSF. We do this by
1750;; loading the Lucid menu emulation code.
1751;;
1752
1753;; Put this into your tcl-mode-hook.
1754(defun tcl-install-menubar ()
1755 (and tcl-using-emacs-19
1756 (not tcl-using-lemacs-19)
1757 (if tcl-using-emacs-19.23
1758 (require 'menubar)
1759 ;; CAVEATS:
1760 ;; * lmenu.el provides 'menubar, which is bogus.
1761 ;; * lmenu.el causes menubars to be turned on everywhere.
1762 ;; Doubly bogus!
1763 ;; Both of these problems are fixed in Emacs 19.23. People
1764 ;; using an Emacs before that just suffer.
1765 (require 'menubar "lmenu")))
1766 (if (not (assoc "Tcl" current-menubar))
1767 (progn
1768 (set-buffer-menubar (copy-sequence current-menubar))
1769 (add-menu nil "Tcl" (cdr tcl-lucid-menu))))
1770 ;; You might want to do something like the below. I have it
1771 ;; commented out because it overrides existing bindings.
1772 ;; For Lucid:
1773 ;; (define-key tcl-mode-map 'button3 'tcl-popup-menu)
1774 ;; For FSF:
1775 ;; (define-key tcl-mode-map [down-mouse-3] 'tcl-popup-menu)
1776 )
1777
1778(defun tcl-popup-menu (e)
1779 (interactive "e")
1780 (and tcl-using-emacs-19
1781 (not tcl-using-lemacs-19)
1782 (if tcl-using-emacs-19.23
1783 (require 'menubar)
1784 ;; CAVEATS:
1785 ;; * lmenu.el provides 'menubar, which is bogus.
1786 ;; * lmenu.el causes menubars to be turned on everywhere.
1787 ;; Doubly bogus!
1788 ;; Both of these problems are fixed in Emacs 19.23. People
1789 ;; using an Emacs before that just suffer.
1790 (require 'menubar "lmenu"))) ;; This is annoying
1791 ;;(mouse-set-point e)
1792 ;; IMHO popup-menu should be autoloaded. Oh well.
1793 (popup-menu tcl-lucid-menu))
1794
1795
1796
1797;;
1798;; Quoting and unquoting functions.
1799;;
1800
1801;; This quoting is sufficient to protect eg a filename from any sort
1802;; of expansion or splitting. Tcl quoting sure sucks.
1803(defun tcl-quote (string)
1804 "Quote STRING according to Tcl rules."
1805 (mapconcat (function (lambda (char)
1806 (if (memq char '(?[ ?] ?{ ?} ?\\ ?\" ?$ ? ?\;))
1807 (concat "\\" (char-to-string char))
1808 (char-to-string char))))
1809 string ""))
1810
1811
1812
1813(provide 'tcl)
1814
1815;;; tcl.el ends here