annotate lisp/modes/ksh-mode.el @ 2:ac2d302a0011 r19-15b2

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