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