annotate lisp/modes/ksh-mode.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; ksh-mode.el --- sh (ksh, bash) script editing mode for GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1992-95 Gary Ellison.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; LCD Archive Entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; ksh-mode|Gary F. Ellison|Gary_F_Ellison@ATT.COM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; Mode for editing sh/ksh/bash scripts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; 23-Feb-95|2.6|~/modes/ksh-mode.el.Z|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; Author: Gary F. Ellison <Gary.F.Ellison@ATT.COM>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; AT&T Bell Laboratories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; 6200 East Broad Street
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; Columbus, Ohio 43213 USA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; Maintainer: Gary F. Ellison <Gary.F.Ellison@ATT.COM>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; Created: Fri Jun 19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; Version: 2.6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; Keywords: languages, shell, korn, bourne, sh, ksh, bash, unix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; Delta On : 2/23/95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; Last Modified By: Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; Last Modified On: Thu Feb 23 11:32:03 1995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; Update Count : 33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; Status : Highly Functional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; Description:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; sh, ksh, and bash script editing commands for emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; Installation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; Put ksh-mode.el in some directory in your load-path.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; Refer to the installation section of ksh-mode's function definition.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; Usage:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; This major mode assists shell script writers with indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; control and control structure construct matching in much the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; fashion as other programming language modes. Invoke describe-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; for more information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; Bugs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; When the ksh-align-to-keyword is non-nil and the nester
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; is a multi-command expression with a compound command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; the lines following the compound end will align incorrectly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; to the compound command instead of it's current indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; The fix will probably require the detection of syntax elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; in the nesting line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; Function ending brace "}" must be on a separate line for indent-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; to do the right thing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; Explicit function definition matching will proclaim in the minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; "No matching compound command" followed by "Matched ... "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; indent-for-comment fails to recognize a comment starting in column 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; hence it moves the comment-start in comment-column.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; HISTORY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; 8-Aug-95 Jack Repenning <jackr@sgi.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; Fix documentation of `ksh-align-to-keyword' to conform to the 23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; Feb default change. Search for keywords obeying case, since the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; shell does.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; 23-Feb-1995 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; Merged Jonathan Stigelman <Stig@hackvan.com> into 2.5 souce.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; 23 Feb 1995 Jonathan Stigelman <Stig@hackvan.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; Reshuffled documentation to make the format more consistant with other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; elisp. Added autoload and removed autoloading instructions from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; ksh-mode docstring. Changed default value for `ksh-align-to-keyword'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; to nil because it doesn't work properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; 2-Aug-1994 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; Last Modified: Mon Jun 13 16:52:55 1994 #29 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; - Syntax table modifications to better support sexp navigation and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;; parsing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; - Fixed keyword regexps. Keywords were not being recoginized on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;; same line as " ' `.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; 13-Jun-1994 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; Last Modified: Wed Mar 30 14:12:26 1994 #28 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; - Minor excursion problem fixed in ksh-indent-command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; 30-Mar-1994 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;; Last Modified: Fri Mar 25 15:42:29 1994 #25 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; - Implement user customizable ksh-comment-regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;; - Make the keyword vs line indentation alignment customizable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;; by calling ksh-align-to-keyword based on variable of same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; name. (If the code is obfuscated or convoluted I can attribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; this to a severe head cold and not malice :)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; 25-Mar-1994 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; Last Modified: Fri Feb 4 13:06:30 1994 #23 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; - Nest relative to the line indentation not the keywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;; column.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;; 4-Feb-1994 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;; Last Modified: Wed Nov 10 10:03:01 1993 #18 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;; - Add direct support for font-lock-mode. Thanks Espen Skoglund
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;; for the regular expressions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;; 10-Nov-1993 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;; Last Modified: Tue Oct 12 15:23:06 1993 #17 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; Fix message on ksh-match-and-tell to not get invalid format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;; when a % appears in the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; 12-Oct-1993 Espen Skoglund <espensk@stud.cs.uit.no>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; Last Modified: Tue Oct 12 15:03:01 1993 #16 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;; Apply Line continuation patch supplied by Espen Skoglund
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;; 1-Sep-1993 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; Last Modified: Tue Aug 17 17:18:18 1993 #14 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; Get rid of this-line hack in ksh-get-nester-column.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; 17-Aug-1993 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;; Last Modified: Mon Jun 21 14:00:43 1993 #13 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; Code uses builtin current-indentation instead of lisp defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; ksh-indentation-on-this-line (thanks to Tom Tromey).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; More and better doc strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;; 5-Aug-1993 Tom Tromey <tromey@cns.caltech.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;; Last Modified: Thu Aug 5 11:09:12 1993 #12 (Tom Tromey)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;; ksh-indent-region skips blank lines. Uses let binding instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;; of setq. No longer marks buffer modified if indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;; doesn't change.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;; 21-Jun-1993 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; Last Modified: Mon Mar 29 15:05:34 1993 #11 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;; Use make-local-variables instead of make-variables-buffer-local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;; ksh-indent now supports nil (keyword aligned) or number (offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;; Support ksh-tab-always-indent feature
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; Variables offsetting indentation renamed to better reflect their
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;; role.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;; Integrate keyword completion feature supplied by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;; Haavard Rue <hrue@imf.unit.no>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;; 29-Mar-1993 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;; Last Modified: Tue Sep 29 16:14:02 1992 #10 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;; Integrate line continuation patch supplied by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;; Haavard Rue <hrue@imf.unit.no>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;; Name back to ksh-mode to avoid confusion with sh-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; by Thomas W. Strong, Jr. <strong+@cmu.edu>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;; 29-Sep-1992 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;; Last Modified: Wed Sep 2 08:51:40 1992 #9 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ;; Full support of ksh88 case items.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;; Align statements under "do" and "then" keywords one position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;; past the keyword.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;; 2-Sep-1992 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;; Last Modified: Tue Aug 4 14:34:35 1992 #8 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;; Use make-variable-buffer-local instead of make-local-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;; Get rid of superflous ksh-default variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;; Use end of word match \b for "then", "do", "else", "elif"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;; Support process substitution lists and exclude ksh 88 case items
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; Use default-tab-width for indentation defaults.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;; Moved installation instructions to the mode level documentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; section.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;; Fixed auto-mode-alist documentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ;; 24-Jul-1992 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;; Last Modified: Fri Jul 24 09:45:11 1992 #7 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;; Modified ksh-indent-region to use marker versus fixed end point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; comment-start-skip regexp no longer fooled by parameter substitution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;; Added constant ksh-mode-version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;; 21-Jul-1992 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; Last Modified: Tue Jul 21 15:53:57 1992 #6 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; Indent with tabs instead of spaces.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; Can handle just about all styles.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;; Anti-newline in REs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; Word delim "\b" in REs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;; More syntax entries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;; Variables with regexp suffix abbreviated to re
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;; Better } handling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;; Implemented minimal indent-region-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;; Mode documentation corrected.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;; Minor lisp source format changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; 29-Jun-1992 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; Last Modified: Mon Jun 29 15:39:35 1992 #5 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; Optimize line-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; Implicit/Explicit functions aok
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;; More indentation variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;; Superfluous defun killed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;; renamed to sh-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ;; 22-Jun-1992 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;; Last Modified: Mon Jun 22 15:01:14 1992 #4 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ;; Cleanup pre att.emacs posting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ;; 19-Jun-1992 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;; Last Modified: Fri Jun 19 17:19:14 1992 #3 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;; Minimal case indent handling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;; 19-Jun-1992 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;; Last Modified: Fri Jun 19 16:23:26 1992 #2 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 ;; Nesting handled except for case statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;; 19-Jun-1992 Gary Ellison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;; Last Modified: Fri Jun 19 10:03:07 1992 #1 (Gary Ellison)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ;; Conception of this mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (defconst ksh-mode-version "2.6"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 "*Version numbers of this version of ksh-mode")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ;; Variables controlling indentation style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (defvar ksh-indent 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; perhaps c-basic-offset would be okay to use as a default, but using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;; default-tab-width as the default is ridiculous --Stig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 "*Indentation of ksh statements with respect to containing block. A value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 of nil indicates compound list keyword \(\"do\" and \"then\"\) alignment.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (defvar ksh-case-item-offset ksh-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 "*Additional indentation for case items within a case statement.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (defvar ksh-case-indent nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 "*Additional indentation for statements under case items.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (defvar ksh-group-offset (- ksh-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 "*Additional indentation for keywords \"do\" and \"then\".")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (defvar ksh-brace-offset 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 "*Additional indentation of \"{\" under functions or brace groupings.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (defvar ksh-multiline-offset 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 "*Additional indentation of line that is preceded of a line ending with a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 \\ to make it continue on next line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (defvar ksh-match-and-tell t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 "*If non-nil echo in the minibuffer the matching compound command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 for the \"done\", \"}\", \"fi\", or \"esac\". ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (defvar ksh-tab-always-indent t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 "*Controls the operation of the TAB key. If t (the default), always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 reindent the current line. If nil, indent the current line only if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 point is at the left margin or in the line's indentation; otherwise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 insert a tab.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (defvar ksh-align-to-keyword nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; #### - this is broken, so it should be disabled by default --Stig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 "*Controls whether nested constructs align from the keyword or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 the current indentation. If non-nil, indentation will be relative to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 the column the keyword starts. If nil, indentation will be relative to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 the current indentation of the line the keyword is on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 The default value is nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 The non-nil case doesn't work very well.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (defvar ksh-comment-regexp "^\\s *#"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 "*Regular expression used to recognize comments. Customize to support
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ksh-like languages.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (defun ksh-current-indentation ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (fset 'ksh-current-indentation 'current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;; Variables controlling completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (defvar ksh-completion-list '())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (make-variable-buffer-local 'ksh-completion-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (set-default 'ksh-completion-list '())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;; -type- : type number, 0:misc, 1:variable, 2:function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;; -regexp-: regexp used to parse the script
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;; -match- : used by match-beginning/end to pickup target
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (defvar ksh-completion-type-misc 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (defvar ksh-completion-regexp-var "\\([A-Za-z_0-9]+\\)=")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (defvar ksh-completion-type-var 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (defvar ksh-completion-match-var 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (defvar ksh-completion-regexp-var2 "\\$\\({\\|{#\\)?\\([A-Za-z_0-9]+\\)[#%:}]?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (defvar ksh-completion-match-var2 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (defvar ksh-completion-regexp-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 "\\(function\\)?[ \t]*\\([A-Za-z_0-9]+\\)[ \t]*([ \t]*)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (defvar ksh-completion-type-function 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (defvar ksh-completion-match-function 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ;; Variable controlling fontification
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (defvar ksh-keywords '("for" "in" "do" "done" "select" "case" "esac" "if"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 "then" "elif" "else" "fi" "while" "until" "function" "time"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 "alias" "bg" "break" "continue" "cd" "echo" "fc" "fg" "getopts" "jobs" "kill"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 "let" "newgrp" "print" "pwd" "read" "readonly" "return" "set" "shift" "test"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 "times" "trap" "typeset" "ulimit" "umask" "unalias" "unset" "wait" "whence"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ;; '("\\<function[ \t]+\\([^(; \t]+\\)" 1 font-lock-function-name-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (defconst ksh-font-lock-keywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;; Fontify [[ ]] expressions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 '("\\(\\[.*\\]\\)" 1 font-lock-doc-string-face t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 ;; Fontify keywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (cons (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 "\\(\\<"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (mapconcat 'identity ksh-keywords "\\>\\|\\<")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 "\\>\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 ;; Fontify function names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 '("\\<function[ \t]+\\([^(; \t]+\\)" 1 font-lock-function-name-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 '("\\(^[ \t]*[A-Za-z_][A-Za-z_0-9]*[ \t]*()\\)" 1 font-lock-function-name-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (put 'ksh-mode 'font-lock-keywords 'ksh-font-lock-keywords)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ;; XEmacs change -- This can incorrectly set some Perl scripts to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ;; ksh-mode. It also won't work for some other shells which ksh-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ;; nominally works with.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ;(defun ksh-check-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ; (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 ; (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 ; (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ; (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 ; (cond ((looking-at "#![ \t]*/.*/k?sh[ \t]*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 ; (ksh-mode))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 ;(add-hook 'find-file-hooks 'ksh-check-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ;; Context/indentation regular expressions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ;; indenting expressions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (defconst ksh-then-do-re "^[^#\n]*\\s\"*\\b\\(then\\|do\\)\\b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 "*Regexp used to locate grouping keywords: \"then\" and \"do\"" )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 ;;(defconst ksh-do-re "^[ \t]*\\bdo\\(\\b\\|$\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (defconst ksh-do-re "^\\s *\\bdo\\(\\b\\|$\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 "*Regexp used to match keyword: do")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (defconst ksh-then-re "^\\s *\\bthen\\(\\b\\|$\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 "*Regexp used to match keyword: then")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 ;; Structure starting/indenting keywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (defconst ksh-else-re "^\\s *\\belse\\(\\b\\|$\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 "*Regexp used to match keyword: else")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (defconst ksh-elif-re "^\\s *\\belif\\(\\b\\|$\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 "*Regexp used to match keyword: elif")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (defconst ksh-brace-re "^\\S>*{[ \t\n]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 "*Regexp used to match syntactic entity: { ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (defconst ksh-case-item-end-re "^\\S>*;;[ \t\n]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 "*Regexp used to match case item end syntactic entity: ;;")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (defconst ksh-keywords-re
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 "^[^#\n]*\\s\"*\\b\\(else\\|if\\|elif\\|case\\|while\\|for\\|until\\|select\\)\\b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 "*Regexp used to detect compound command keywords: if, else, elif case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 while, for, until, and select")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (defconst ksh-if-re "^[^#\n]*\\s\"*\\b\\(if\\)\\b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 "*Regexp used to match keyword: if")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (defconst ksh-iteration-keywords-re
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 "^[^#\n]*\\s\"*\\b\\(while\\|for\\|until\\|select\\)\\b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 "*Match one of the keywords: while, until, for, select")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (defconst ksh-case-re "^[^#\n]*\\s\"*\\b\\(case\\)\\b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 "*Regexp used to match keyword: case")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (defconst ksh-explicit-func-re
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 "^\\s *\\(function\\s [a-zA-z_][a-zA-Z0-1_]*\\)\\b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 "*Match an explicit function definition: function name")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (defconst ksh-implicit-func-re
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 "^\\s *\\([a-zA-z_][a-zA-Z0-1_]*\\)\\s *()\\s *"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 "*Match an implicit function definition: name ()")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (defconst ksh-func-brace-re "^\\s *\\(.*{\\)[ \t\n]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 "*Match a implicit function definition brace: name { ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ;; indenting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (defconst ksh-case-item-re "^[^#\n]*\\s\"*\\()\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 "*Regexp used to match case-items including ksh88")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (defconst ksh-paren-re "^[^#\n]*\\s\"*)[ \t\n]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 "*Regexp used to match compound list & case items")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 ;; structure ending keyword regular expressions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (defconst ksh-fi-re "^\\s *fi\\b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 "*Regexp used to match keyword: fi")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (defconst ksh-esac-re "^\\s *esac\\b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 "*Regexp used to match keyword: esac")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (defconst ksh-done-re "^\\s *done\\b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 "*Regexp used to match keyword: done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (defconst ksh-brace-end-re "^\\s *}\\s *"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 "*Regexp used to match function brace-groups")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (defconst ksh-multiline-re "^.*\\\\$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 "*Regexp used to match a line with a statement using more lines.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ;; Create mode specific tables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (defvar ksh-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 "Syntax table used while in ksh mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (if ksh-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (setq ksh-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (modify-syntax-entry ?\' "\"" ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (modify-syntax-entry ?` "\"" ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (modify-syntax-entry ?\n ">" ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (modify-syntax-entry ?\f ">" ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (modify-syntax-entry ?# "<" ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (modify-syntax-entry ?_ "w" ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (modify-syntax-entry ?< "." ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (modify-syntax-entry ?> "." ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (modify-syntax-entry ?& "." ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (modify-syntax-entry ?| "." ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (modify-syntax-entry ?$ "." ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (modify-syntax-entry ?% "." ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (modify-syntax-entry ?= "." ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (modify-syntax-entry ?/ "." ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (modify-syntax-entry ?+ "." ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (modify-syntax-entry ?* "." ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (modify-syntax-entry ?- "." ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (modify-syntax-entry ?\; "." ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (defvar ksh-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 "Abbrev table used while in ksh mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (define-abbrev-table 'ksh-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (defvar ksh-mode-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 "Keymap used in ksh mode")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (if ksh-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (setq ksh-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (define-key ksh-mode-map "\t" 'ksh-indent-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 ;; (define-key ksh-mode-map "\n" 'reindent-then-newline-and-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 ;; (define-key ksh-mode-map '[return] 'reindent-then-newline-and-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 ;; (define-key ksh-mode-map "\t" 'ksh-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 ;; (define-key ksh-mode-map "\177" 'backward-delete-char-untabify)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (define-key ksh-mode-map "\C-j" 'reindent-then-newline-and-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (define-key ksh-mode-map "\e\t" 'ksh-complete-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (define-key ksh-mode-map "\C-c\t" 'ksh-completion-init-and-pickup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (defun ksh-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 "ksh-mode 2.6 - Major mode for editing (Bourne, Korn or Bourne again)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 shell scripts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 Special key bindings and commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 \\{ksh-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 Variables controlling indentation style:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 ksh-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 Indentation of ksh statements with respect to containing block.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 Default value is 2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ksh-case-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 Additional indentation for statements under case items.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 Default value is nil which will align the statements one position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 past the \")\" of the pattern.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ksh-case-item-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 Additional indentation for case items within a case statement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 Default value is 2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ksh-group-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 Additional indentation for keywords \"do\" and \"then\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 Default value is -2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ksh-brace-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 Additional indentation of \"{\" under functions or brace groupings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 Default value is 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 ksh-multiline-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 Additional indentation of line that is preceded of a line ending with a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 \\ to make it continue on next line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 ksh-tab-always-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 Controls the operation of the TAB key. If t (the default), always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 reindent the current line. If nil, indent the current line only if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 point is at the left margin or in the line's indentation; otherwise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 insert a tab.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 ksh-match-and-tell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 If non-nil echo in the minibuffer the matching compound command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 for the \"done\", \"}\", \"fi\", or \"esac\". Default value is t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 ksh-align-to-keyword
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 Controls whether nested constructs align from the keyword or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 the current indentation. If non-nil, indentation will be relative to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 the column the keyword starts. If nil, indentation will be relative to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 the current indentation of the line the keyword is on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 The default value is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ksh-comment-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 Regular expression used to recognize comments. Customize to support
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ksh-like languages. Default value is \"\^\\\\s *#\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 Style Guide.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 By setting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (setq ksh-indent default-tab-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (setq ksh-group-offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 The following style is obtained:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 if [ -z $foo ]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 bar # <-- ksh-group-offset is additive to ksh-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 fi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 By setting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (setq ksh-indent default-tab-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (setq ksh-group-offset (- 0 ksh-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 The following style is obtained:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 if [ -z $foo ]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 bar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 fi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 By setting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (setq ksh-case-item-offset 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (setq ksh-case-indent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 The following style is obtained:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 case x in *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 foo) bar # <-- ksh-case-item-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 baz;; # <-- ksh-case-indent aligns with \")\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 foobar) foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 bar;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 esac
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 By setting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (setq ksh-case-item-offset 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (setq ksh-case-indent 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 The following style is obtained:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 case x in *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 foo) bar # <-- ksh-case-item-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 baz;; # <-- ksh-case-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 foobar) foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 bar;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 esac
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 Installation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 Put ksh-mode.el in some directory in your load-path.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 Put the following forms in your .emacs file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (setq auto-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (append auto-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 '(\"\\\\.sh$\" . ksh-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 '(\"\\\\.ksh$\" . ksh-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 '(\"\\\\.bashrc\" . ksh-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 '(\"\\\\..*profile\" . ksh-mode))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (setq ksh-mode-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (function (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (font-lock-mode 1) ;; font-lock the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (setq ksh-indent 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (setq ksh-group-offset -8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (setq ksh-brace-offset -8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (setq ksh-tab-always-indent t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (setq ksh-match-and-tell t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (setq ksh-align-to-keyword t) ;; Turn on keyword alignment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 )))"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (use-local-map ksh-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (setq major-mode 'ksh-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (setq mode-name "Ksh")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (setq local-abbrev-table ksh-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (set-syntax-table ksh-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (make-local-variable 'indent-line-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (setq indent-line-function 'ksh-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (make-local-variable 'indent-region-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (setq indent-region-function 'ksh-indent-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (make-local-variable 'comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (setq comment-start "# ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (make-local-variable 'comment-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (setq comment-end "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (make-local-variable 'comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (setq comment-column 32)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (make-local-variable 'comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (setq comment-start-skip "#+ *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 ;; config font-lock mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (make-local-variable 'font-lock-keywords)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (setq font-lock-keywords ksh-font-lock-keywords)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 ;; Let the user customize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (run-hooks 'ksh-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (if (not ksh-align-to-keyword)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (ksh-align-to-keyword -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 ) ;; defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 ;; Support functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (defun ksh-align-to-keyword (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 "Toggle value of ksh-align-to-keyword and rebind the ksh-current-indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 function. With arg, force alignment to keyword if and only if arg is positive."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (if (null arg) ;just toggle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (cond ((not ksh-align-to-keyword)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (setq ksh-align-to-keyword t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (fset 'ksh-current-indentation 'current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (setq ksh-align-to-keyword nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (fset 'ksh-current-indentation 'current-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (cond ((natnump arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (setq ksh-align-to-keyword t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (fset 'ksh-current-indentation 'current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (setq ksh-align-to-keyword nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (fset 'ksh-current-indentation 'current-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (defun ksh-current-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 "Return the vertical position of point in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 Top line is 1."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (+ (count-lines (point-min) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (if (= (current-column) 0) 1 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (defun ksh-line-to-string ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 "From point, construct a string from all characters on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 current line"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (skip-chars-forward " \t") ;; skip tabs as well as spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (end-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (defun ksh-get-nest-level ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 "Return a 2 element list (nest-level nest-line) describing where the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 current line should nest."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (let ((case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (while (and (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (null level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (if (and (not (looking-at "^\\s *$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (not (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (looking-at ksh-multiline-re)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (not (looking-at ksh-comment-regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (setq level (cons (current-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (ksh-current-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 );; if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 );; while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (if (null level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (cons (current-indentation) (ksh-current-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (defun ksh-looking-at-compound-list ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 "Return true if current line contains compound list initiating keyword"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (looking-at ksh-do-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (looking-at ksh-then-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 ) ;; or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 ) ;; defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (defun ksh-looking-at-case-item ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 "Return true if current line is a case-item .vs. paren compound list"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 ;; Handle paren indentation constructs for this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (cond ((looking-at ksh-paren-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (goto-line (cdr (ksh-get-nest-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 ;; The question is whether this is really a case item or just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 ;; parenthesized compound list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (cond ((or (looking-at ksh-case-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (looking-at ksh-case-item-end-re)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 ;; turns out to be a parenthesized compound list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 ;; so propigate the nil for cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 ) ;; defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (defun ksh-get-case-indent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 "Return the column of the closest open case statement"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (let (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (nest-list (ksh-get-compound-level ksh-case-re ksh-esac-re (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (if (null nest-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (if ksh-match-and-tell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (message "No matching case for ;;"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (car nest-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ;; Functions which make this mode what it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (defun ksh-get-nester-column (nest-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 "Return the column to indent to with respect to nest-line taking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 into consideration keywords and other nesting constructs."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (let ((fence-post)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (nester-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (start-line (ksh-current-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 ;; Handle case item indentation constructs for this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (cond ((ksh-looking-at-case-item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (goto-line nest-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (let ((fence-post (save-excursion (end-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 ;; Now know there is a case-item so detect whether
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 ;; it is first under case, just another case-item, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 ;; a case-item and case-item-end all rolled together.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (cond ((re-search-forward ksh-case-re fence-post t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (goto-char (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (+ (ksh-current-indentation) ksh-case-item-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 ((ksh-looking-at-case-item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (current-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 ((looking-at ksh-case-item-end-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (+ (ksh-get-case-indent) ksh-case-item-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (t;; Not a case-item. What to do relative to the nest-line?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (goto-line nest-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (setq fence-post (save-excursion (end-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (setq nester-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 ;; Check if we are in a continued statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 ((and (looking-at ksh-multiline-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (goto-line (1- start-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (looking-at ksh-multiline-re)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (+ (current-indentation) ksh-multiline-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 ;; In order to locate the column of the keyword,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 ;; which might be embedded within a case-item,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 ;; it is necessary to use re-search-forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 ;; Search by literal case, since shell is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 ;; case-sensitive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 ((re-search-forward ksh-keywords-re fence-post t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 (goto-char (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (if (looking-at ksh-case-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (+ (ksh-current-indentation) ksh-case-item-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (+ (ksh-current-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (if (null ksh-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 2 ksh-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 ((re-search-forward ksh-then-do-re fence-post t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (if (null ksh-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (goto-char (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (+ (ksh-current-indentation) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (goto-char (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (+ (ksh-current-indentation) ksh-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 ((looking-at ksh-brace-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (+ (current-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (if (null ksh-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 2 ksh-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 ;; Forces functions to first column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 ((or (looking-at ksh-implicit-func-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (looking-at ksh-explicit-func-re))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (if (looking-at ksh-func-brace-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (if (null ksh-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 2 ksh-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 ksh-brace-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 ;; Need to first detect the end of a case-item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 ((looking-at ksh-case-item-end-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (+ (ksh-get-case-indent) ksh-case-item-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 ;; Now detect first statement under a case item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 ((ksh-looking-at-case-item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (if (null ksh-case-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (re-search-forward ksh-case-item-re fence-post t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (goto-char (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (+ (current-column) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (+ (current-indentation) ksh-case-indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 ;; This is hosed when using current-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 ;; and there is a multi-command expression as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 ;; nester.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (t (current-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 ));; excursion over
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 ;; Handle additional indentation constructs for this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (cond ((ksh-looking-at-compound-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (+ nester-column ksh-group-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 ((looking-at ksh-brace-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (+ nester-column ksh-brace-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (t nester-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 );; Not a case-item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 );;let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 );; excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 );; defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (defun ksh-indent-command ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 "Indent current line relative to containing block and allow for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 ksh-tab-always-indent customization"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (cond ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (ksh-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (ksh-tab-always-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (ksh-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (t (insert-tab))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (defun ksh-indent-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 "Indent current line as far as it should go according
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 to the syntax/context"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (if (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 ;; Align this line to current nesting level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (let*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (level-list (ksh-get-nest-level)) ; Where to nest against
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 ;; (last-line-level (car level-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (this-line-level (current-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (nester-column (ksh-get-nester-column (cdr level-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (struct-match (ksh-match-structure-and-reindent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (if struct-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (setq nester-column struct-match))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (if (eq nester-column this-line-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (let ((beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (delete-region beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (indent-to nester-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 );; let*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 );; if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 );; excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 ;; Position point on this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (let*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (this-line-level (current-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (this-bol (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (this-point (- (point) this-bol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (cond ((> this-line-level this-point);; point in initial white space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (back-to-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (t nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 );; cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 );; let*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 );; let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 );; defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (defun ksh-match-indent-level (begin-re end-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 "Match the compound command and indent. Return nil on no match,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 indentation to use for this line otherwise."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (let* ((case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (nest-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (ksh-get-compound-level begin-re end-re (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 ) ;; bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (if (null nest-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (if ksh-match-and-tell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (message "No matching compound command"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 nil) ;; Propagate a miss.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (let* (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (nest-level (car nest-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (match-line (cdr nest-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 ) ;; bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (if ksh-match-and-tell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (goto-line match-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (message "Matched ... %s" (ksh-line-to-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 ) ;; excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 ) ;; if ksh-match-and-tell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 nest-level ;;Propagate a hit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 ) ;; let*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 ) ;; if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 ) ;; let*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 ) ;; defun ksh-match-indent-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (defun ksh-match-structure-and-reindent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 "If the current line matches one of the indenting keywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 or one of the control structure ending keywords then reindent. Also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 if ksh-match-and-tell is non-nil the matching structure will echo in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 the minibuffer"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (cond ((looking-at ksh-else-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (ksh-match-indent-level ksh-if-re ksh-fi-re))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 ((looking-at ksh-elif-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (ksh-match-indent-level ksh-if-re ksh-fi-re))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 ((looking-at ksh-fi-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (ksh-match-indent-level ksh-if-re ksh-fi-re))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 ((looking-at ksh-done-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (ksh-match-indent-level ksh-iteration-keywords-re ksh-done-re))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 ((looking-at ksh-esac-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (ksh-match-indent-level ksh-case-re ksh-esac-re))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 ((looking-at ksh-brace-end-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 ((ksh-match-indent-level ksh-implicit-func-re ksh-brace-end-re))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 ((ksh-match-indent-level ksh-explicit-func-re ksh-brace-end-re))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 ((ksh-match-indent-level ksh-func-brace-re ksh-brace-end-re))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (t nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 );; cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (defun ksh-get-compound-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (begin-re end-re anchor-point &optional balance-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 "Determine how much to indent this structure. Return a list (level line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 of the matching compound command or nil if no match found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (let*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (;; Locate the next compound begin keyword bounded by point-min
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (match-point (if (re-search-backward begin-re (point-min) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (match-beginning 1) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (nest-column (if (zerop match-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (goto-char match-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (ksh-current-indentation))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (nest-list (cons 0 0)) ;; sentinel cons since cdr is >= 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (if (zerop match-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 nil ;; graceful exit from recursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (if (nlistp balance-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (setq balance-list (list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 ;; Now search forward from matching start keyword for end keyword
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 (while (and (consp nest-list) (zerop (cdr nest-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (re-search-forward end-re anchor-point t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (if (not (memq (point) balance-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (setq balance-list (cons (point) balance-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (goto-char match-point) ;; beginning of compound cmd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (setq nest-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (ksh-get-compound-level begin-re end-re
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 anchor-point balance-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (cond ((consp nest-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (if (zerop (cdr nest-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (goto-char match-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (cons nest-column (ksh-current-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 nest-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 (t nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (defun ksh-indent-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 "From start to end, indent each line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 ;; The algorithm is just moving through the region line by line with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 ;; the match noise turned off. Only modifies nonempty lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (let (ksh-match-and-tell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 (endmark (copy-marker end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (while (> (marker-position endmark) start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (if (not (and (bolp) (eolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (ksh-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (setq start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (set-marker endmark nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 ;; Completion code supplied by Haavard Rue <hrue@imf.unit.no>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 ;; add a completion with a given type to the list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (defun ksh-addto-alist (completion type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (setq ksh-completion-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (append ksh-completion-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (list (cons completion type)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 ;; init the list and pickup all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (defun ksh-completion-init-and-pickup ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 (ksh-completion-list-init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (ksh-pickup-all)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 ;; init the list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (defun ksh-completion-list-init ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (setq ksh-completion-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (cons "if" ksh-completion-type-misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (cons "while" ksh-completion-type-misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (cons "until" ksh-completion-type-misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (cons "select" ksh-completion-type-misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 (cons "for" ksh-completion-type-misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (cons "continue" ksh-completion-type-misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (cons "function" ksh-completion-type-misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (cons "fi" ksh-completion-type-misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (cons "case" ksh-completion-type-misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (cons "esac" ksh-completion-type-misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (cons "break" ksh-completion-type-misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (cons "exit" ksh-completion-type-misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (cons "done" ksh-completion-type-misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (cons "do" ksh-completion-type-misc))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (defun ksh-eol-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (defun ksh-bol-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (defun ksh-pickup-all ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 "Pickup all completions in buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (ksh-pickup-completion-driver (point-min) (point-max) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (defun ksh-pickup-this-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 "Pickup all completions in current line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (ksh-pickup-completion-driver (ksh-bol-point) (ksh-eol-point) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (defun ksh-pickup-completion-driver (pmin pmax message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 "Driver routine for ksh-pickup-completion."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (if message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 (message "pickup completion..."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (let* (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 (i1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (ksh-pickup-completion ksh-completion-regexp-var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 ksh-completion-type-var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 ksh-completion-match-var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 pmin pmax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (i2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (ksh-pickup-completion ksh-completion-regexp-var2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 ksh-completion-type-var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 ksh-completion-match-var2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 pmin pmax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (i3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (ksh-pickup-completion ksh-completion-regexp-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 ksh-completion-type-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 ksh-completion-match-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 pmin pmax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (if message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (message "pickup %d variables and %d functions." (+ i1 i2) i3))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (defun ksh-pickup-completion (regexp type match pmin pmax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 "Pickup completion in region and addit to the list, if not already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 there."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (let ((i 0) kw obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (goto-char pmin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (while (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (re-search-forward regexp pmax t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (match-beginning match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (setq kw (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (match-beginning match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (match-end match))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (setq obj (assoc kw ksh-completion-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (if (or (equal nil obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (and (not (equal nil obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (not (= type (cdr obj)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 (setq i (1+ i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (ksh-addto-alist kw type))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 (defun ksh-complete-symbol ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 "Perform completion."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (let* ((case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (beg (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (while (= (char-syntax (following-char)) ?\')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (pattern (buffer-substring beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 ;; ` or $( mark a function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (if (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (looking-at "`"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (backward-char 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (looking-at "\\$(")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (function (lambda (sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (equal (cdr sym) ksh-completion-type-function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 ;; a $, ${ or ${# mark a variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 (if (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (looking-at "\\$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (backward-char 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (looking-at "\\${"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (backward-char 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (looking-at "\\${#")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (function (lambda (sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (equal (cdr sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 ksh-completion-type-var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 ;; don't know. use 'em all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (function (lambda (sym) t))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (completion (try-completion pattern ksh-completion-list predicate)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 (cond ((eq completion t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 ;; oops, what is this ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 ((null completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 (message "Can't find completion for \"%s\"" pattern))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 ;; insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 ((not (string= pattern completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (delete-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 (insert completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 ;; write possible completion in the minibuffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 ;; use this instead of a seperate buffer (usual)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (let ((list (all-completions pattern ksh-completion-list predicate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (string ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 (setq string (concat string (format "%s " (car list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 (setq list (cdr list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (message string))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (provide 'ksh-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 ;;; ksh-mode.el ends here