annotate lisp/modes/ksh-mode.el @ 102:a145efe76779 r20-1b3

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