annotate lisp/modes/sh-script.el @ 189:489f57a838ef r20-3b21

Import from CVS: tag r20-3b21
author cvs
date Mon, 13 Aug 2007 09:57:07 +0200
parents 25f70ba0133c
children acd284d43ca1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1 ;;; sh-script.el --- shell-script editing commands for Emacs
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
3 ;; Copyright (C) 1993, 1994, 1995, 1996 by Free Software Foundation, Inc.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
4
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
5 ;; Author: Daniel.Pfeiffer@Informatik.START.dbp.de, fax (+49 69) 7588-2389
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
6 ;; Version: 2.0e
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
7 ;; Maintainer: FSF
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
8 ;; Keywords: languages, unix
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
9
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
10 ;; This file is part of XEmacs.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
11
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
12 ;; XEmacs is free software; you can redistribute it and/or modify it
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
13 ;; under the terms of the GNU General Public License as published by
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
15 ;; any later version.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
16
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
17 ;; XEmacs is distributed in the hope that it will be useful, but
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
20 ;; General Public License for more details.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
21
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
25 ;; 02111-1307, USA.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
26
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
27 ;;; Synched up with: FSF 19.34.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
28
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
29 ;;; Commentary:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
30
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
31 ;; Major mode for editing shell scripts. Bourne, C and rc shells as well
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
32 ;; as various derivatives are supported and easily derived from. Structured
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
33 ;; statements can be inserted with one command or abbrev. Completion is
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
34 ;; available for filenames, variables known from the script, the shell and
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
35 ;; the environment as well as commands.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
36
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
37 ;;; Known Bugs:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
38
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
39 ;; - In Bourne the keyword `in' is not anchored to case, for, select ...
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
40 ;; - Variables in `"' strings aren't fontified because there's no way of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
41 ;; syntactically distinguishing those from `'' strings.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
42
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
43 ;;; Code:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
44
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
45 ;; page 1: variables and settings
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
46 ;; page 2: mode-command and utility functions
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
47 ;; page 3: statement syntax-commands for various shells
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
48 ;; page 4: various other commands
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
49
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
50 (require 'executable)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
51
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
52 (defgroup sh nil
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
53 "Shell programming mode."
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
54 :group 'unix
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
55 :group 'languages)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
56
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
57
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
58 ;;; interpreter-mode-alist is not compatible between Emacs and XEmacs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
59 ;;; So fake it.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
60
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
61 (defvar sh-interpreter-mode-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
62 '(("perl" . perl-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
63 ("perl5" . perl-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
64 ("wish" . tcl-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
65 ("wishx" . tcl-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
66 ("tcl" . tcl-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
67 ("tclsh" . tcl-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
68 ("awk" . awk-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
69 ("mawk" . awk-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
70 ("nawk" . awk-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
71 ("gawk" . awk-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
72 ("scm" . scheme-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
73 ("ash" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
74 ("bash" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
75 ("csh" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
76 ("dtksh" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
77 ("es" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
78 ("itcsh" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
79 ("jsh" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
80 ("ksh" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
81 ("oash" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
82 ("pdksh" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
83 ("rc" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
84 ("sh" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
85 ("sh5" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
86 ("tcsh" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
87 ("wksh" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
88 ("wsh" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
89 ("zsh" . sh-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
90 ("tail" . text-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
91 ("more" . text-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
92 ("less" . text-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
93 ("pg" . text-mode))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
94 "Alist mapping interpreter names to major modes.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
95 This alist applies to files whose first line starts with `#!'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
96 Each element looks like (INTERPRETER . MODE).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
97 The car of each element is compared with
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
98 the name of the interpreter specified in the first line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
99 If it matches, mode MODE is selected.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
100
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
101 (defcustom sh-mode-hook nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
102 "*Hook run by `sh-mode'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
103 :type 'hook
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
104 :group 'sh)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
105
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
106 (defcustom sh-set-shell-hook nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
107 "*Hook run by `sh-set-shell'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
108 :type 'hook
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
109 :group 'sh)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
110
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
111 (defcustom sh-ancestor-alist
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
112 '((ash . sh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
113 (bash . jsh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
114 (dtksh . ksh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
115 (es . rc)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
116 (itcsh . tcsh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
117 (jcsh . csh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
118 (jsh . sh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
119 (ksh . ksh88)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
120 (ksh88 . jsh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
121 (oash . sh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
122 (pdksh . ksh88)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
123 (posix . sh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
124 (tcsh . csh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
125 (wksh . ksh88)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
126 (wsh . sh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
127 (zsh . ksh88))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
128 "*Alist showing the direct ancestor of various shells.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
129 This is the basis for `sh-feature'. See also `sh-alias-alist'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
130 By default we have the following three hierarchies:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
131
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
132 csh C Shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
133 jcsh C Shell with Job Control
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
134 tcsh Toronto C Shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
135 itcsh ? Toronto C Shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
136 rc Plan 9 Shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
137 es Extensible Shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
138 sh Bourne Shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
139 ash ? Shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
140 jsh Bourne Shell with Job Control
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
141 bash GNU Bourne Again Shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
142 ksh88 Korn Shell '88
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
143 ksh Korn Shell '93
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
144 dtksh CDE Desktop Korn Shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
145 pdksh Public Domain Korn Shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
146 wksh Window Korn Shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
147 zsh Z Shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
148 oash SCO OA (curses) Shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
149 posix IEEE 1003.2 Shell Standard
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
150 wsh ? Shell"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
151 :type '(repeat (cons symbol symbol))
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
152 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
153
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
154
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
155 (defcustom sh-alias-alist
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
156 ;; XEmacs: Linux is spelled `linux'
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
157 (nconc (if (eq system-type 'linux)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
158 '((csh . tcsh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
159 (ksh . pdksh)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
160 ;; for the time being
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
161 '((ksh . ksh88)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
162 (sh5 . sh)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
163 "*Alist for transforming shell names to what they really are.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
164 Use this where the name of the executable doesn't correspond to the type of
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
165 shell it really is."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
166 :type '(repeat (cons symbol symbol))
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
167 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
168
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
169
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
170 (defcustom sh-shell-file (or (getenv "SHELL") "/bin/sh")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
171 "*The executable file name for the shell being programmed."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
172 :type 'string
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
173 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
174
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
175
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
176 (defcustom sh-shell-arg
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
177 ;; bash does not need any options when run in a shell script,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
178 '((bash)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
179 (csh . "-f")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
180 (pdksh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
181 ;; Bill_Mann@praxisint.com says -p with ksh can do harm.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
182 (ksh88)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
183 ;; -p means don't initialize functions from the environment.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
184 (rc . "-p")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
185 ;; Someone proposed -motif, but we don't want to encourage
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
186 ;; use of a non-free widget set.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
187 (wksh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
188 ;; -f means don't run .zshrc.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
189 (zsh . "-f"))
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
190 "*Single argument string for the magic number. See `sh-feature'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
191 :type '(repeat (cons (symbol :tag "Shell")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
192 (choice (const :tag "No Arguments" nil)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
193 (string :tag "Arguments")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
194 (cons :format "Evaluate: %v"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
195 (const :format "" eval)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
196 sexp))))
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
197 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
198
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
199 (defvar sh-shell-variables nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
200 "Alist of shell variable names that should be included in completion.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
201 These are used for completion in addition to all the variables named
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
202 in `process-environment'. Each element looks like (VAR . VAR), where
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
203 the car and cdr are the same symbol.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
204
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
205 (defvar sh-shell-variables-initialized nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
206 "Non-nil if `sh-shell-variables' is initialized.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
207
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
208 (defun sh-canonicalize-shell (shell)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
209 "Convert a shell name SHELL to the one we should handle it as."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
210 (or (symbolp shell)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
211 (setq shell (intern shell)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
212 (or (cdr (assq shell sh-alias-alist))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
213 shell))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
214
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
215 (defvar sh-shell (sh-canonicalize-shell (file-name-nondirectory sh-shell-file))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
216 "The shell being programmed. This is set by \\[sh-set-shell].")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
217
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
218 ;;; I turned off this feature because it doesn't permit typing commands
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
219 ;;; in the usual way without help.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
220 ;;;(defvar sh-abbrevs
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
221 ;;; '((csh eval sh-abbrevs shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
222 ;;; "switch" 'sh-case
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
223 ;;; "getopts" 'sh-while-getopts)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
224
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
225 ;;; (es eval sh-abbrevs shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
226 ;;; "function" 'sh-function)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
227
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
228 ;;; (ksh88 eval sh-abbrevs sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
229 ;;; "select" 'sh-select)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
230
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
231 ;;; (rc eval sh-abbrevs shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
232 ;;; "case" 'sh-case
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
233 ;;; "function" 'sh-function)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
234
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
235 ;;; (sh eval sh-abbrevs shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
236 ;;; "case" 'sh-case
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
237 ;;; "function" 'sh-function
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
238 ;;; "until" 'sh-until
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
239 ;;; "getopts" 'sh-while-getopts)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
240
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
241 ;;; ;; The next entry is only used for defining the others
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
242 ;;; (shell "for" sh-for
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
243 ;;; "loop" sh-indexed-loop
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
244 ;;; "if" sh-if
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
245 ;;; "tmpfile" sh-tmp-file
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
246 ;;; "while" sh-while)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
247
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
248 ;;; (zsh eval sh-abbrevs ksh88
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
249 ;;; "repeat" 'sh-repeat))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
250 ;;; "Abbrev-table used in Shell-Script mode. See `sh-feature'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
251 ;;;Due to the internal workings of abbrev tables, the shell name symbol is
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
252 ;;;actually defined as the table for the like of \\[edit-abbrevs].")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
253
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
254
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
255
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
256 (defvar sh-mode-syntax-table
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
257 '((csh eval identity sh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
258 (sh eval sh-mode-syntax-table ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
259 ;; #'s meanings depend on context which can't be expressed here
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
260 ;; ?\# "<"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
261 ;; ?\^l ">#"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
262 ;; ?\n ">#"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
263 ?\" "\"\""
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
264 ?\' "\"'"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
265 ?\` ".`"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
266 ?$ "_"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
267 ?! "_"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
268 ?% "_"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
269 ?: "_"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
270 ?. "_"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
271 ?^ "_"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
272 ?~ "_")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
273 (rc eval sh-mode-syntax-table sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
274 ?\" "_"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
275 ?\` "."))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
276 "Syntax-table used in Shell-Script mode. See `sh-feature'.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
277
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
278
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
279
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
280 (defvar sh-mode-map
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
281 (let ((map (make-sparse-keymap))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
282 (menu-map (make-sparse-keymap "Insert")))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
283 (define-key map "\C-c(" 'sh-function)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
284 (define-key map "\C-c\C-w" 'sh-while)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
285 (define-key map "\C-c\C-u" 'sh-until)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
286 (define-key map "\C-c\C-t" 'sh-tmp-file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
287 (define-key map "\C-c\C-s" 'sh-select)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
288 (define-key map "\C-c\C-r" 'sh-repeat)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
289 (define-key map "\C-c\C-o" 'sh-while-getopts)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
290 (define-key map "\C-c\C-l" 'sh-indexed-loop)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
291 (define-key map "\C-c\C-i" 'sh-if)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
292 (define-key map "\C-c\C-f" 'sh-for)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
293 (define-key map "\C-c\C-c" 'sh-case)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
294
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
295 (define-key map "=" 'sh-assignment)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
296 (define-key map "\C-c+" 'sh-add)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
297 (define-key map "\C-\M-x" 'sh-execute-region)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
298 (define-key map "\C-c\C-x" 'executable-interpret)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
299 (define-key map "<" 'sh-maybe-here-document)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
300 (define-key map "(" 'skeleton-pair-insert-maybe)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
301 (define-key map "{" 'skeleton-pair-insert-maybe)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
302 (define-key map "[" 'skeleton-pair-insert-maybe)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
303 (define-key map "'" 'skeleton-pair-insert-maybe)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
304 (define-key map "`" 'skeleton-pair-insert-maybe)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
305 (define-key map "\"" 'skeleton-pair-insert-maybe)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
306
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
307 (define-key map "\t" 'sh-indent-line)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
308 (substitute-key-definition 'complete-tag 'comint-dynamic-complete
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
309 map (current-global-map))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
310 (substitute-key-definition 'newline-and-indent 'sh-newline-and-indent
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
311 map (current-global-map))
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 138
diff changeset
312 ;; GDF - Don't mess around with the DEL bindings
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 138
diff changeset
313 ;; (substitute-key-definition 'delete-backward-char
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 138
diff changeset
314 ;; 'backward-delete-char-untabify
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 138
diff changeset
315 ;; map (current-global-map))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
316 (define-key map "\C-c:" 'sh-set-shell)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
317 (substitute-key-definition 'beginning-of-defun
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
318 'sh-beginning-of-compound-command
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
319 map (current-global-map))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
320 (substitute-key-definition 'backward-sentence 'sh-beginning-of-command
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
321 map (current-global-map))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
322 (substitute-key-definition 'forward-sentence 'sh-end-of-command
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
323 map (current-global-map))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
324 (define-key map [menu-bar insert] (cons "Insert" menu-map))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
325 (define-key menu-map [sh-while] '("While Loop" . sh-while))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
326 (define-key menu-map [sh-until] '("Until Loop" . sh-until))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
327 (define-key menu-map [sh-tmp-file] '("Temporary File" . sh-tmp-file))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
328 (define-key menu-map [sh-select] '("Select Statement" . sh-select))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
329 (define-key menu-map [sh-repeat] '("Repeat Loop" . sh-repeat))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
330 (define-key menu-map [sh-while-getopts]
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
331 '("Options Loop" . sh-while-getopts))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
332 (define-key menu-map [sh-indexed-loop]
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
333 '("Indexed Loop" . sh-indexed-loop))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
334 (define-key menu-map [sh-if] '("If Statement" . sh-if))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
335 (define-key menu-map [sh-for] '("For Loop" . sh-for))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
336 (define-key menu-map [sh-case] '("Case Statement" . sh-case))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
337 map)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
338 "Keymap used in Shell-Script mode.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
339
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
340
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
341
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
342 (defcustom sh-dynamic-complete-functions
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
343 '(shell-dynamic-complete-environment-variable
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
344 shell-dynamic-complete-command
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
345 comint-dynamic-complete-filename)
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
346 "*Functions for doing TAB dynamic completion."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
347 :type '(repeat function)
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
348 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
349
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
350
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
351 (defcustom sh-require-final-newline
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
352 '((csh . t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
353 (pdksh . t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
354 (rc eval . require-final-newline)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
355 (sh eval . require-final-newline))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
356 "*Value of `require-final-newline' in Shell-Script mode buffers.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
357 See `sh-feature'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
358 :type '(repeat (cons (symbol :tag "Shell")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
359 (choice (const :tag "require" t)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
360 (cons :format "Evaluate: %v"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
361 (const :format "" eval)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
362 sexp))))
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
363 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
364
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
365
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
366 (defcustom sh-comment-prefix
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
367 '((csh . "\\(^\\|[^$]\\|\\$[^{]\\)")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
368 (rc eval identity csh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
369 (sh . "\\(^\\|[ \t|&;()]\\)"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
370 "*Regexp matching what may come before a comment `#'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
371 This must contain one \\(grouping\\) since it is the basis for fontifying
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
372 comments as well as for `comment-start-skip'.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
373 See `sh-feature'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
374 :type '(repeat (cons (symbol :tag "Shell")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
375 (choice regexp
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
376 (cons :format "Evaluate: %v"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
377 (const :format "" eval)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
378 sexp))))
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
379 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
380
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
381
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
382 (defcustom sh-assignment-regexp
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
383 '((csh . "\\<\\([a-zA-Z0-9_]+\\)\\(\\[.+\\]\\)?[ \t]*[-+*/%^]?=")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
384 ;; actually spaces are only supported in let/(( ... ))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
385 (ksh88 . "\\<\\([a-zA-Z0-9_]+\\)\\(\\[.+\\]\\)?[ \t]*\\([-+*/%&|~^]\\|<<\\|>>\\)?=")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
386 (rc . "\\<\\([a-zA-Z0-9_*]+\\)[ \t]*=")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
387 (sh . "\\<\\([a-zA-Z0-9_]+\\)="))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
388 "*Regexp for the variable name and what may follow in an assignment.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
389 First grouping matches the variable name. This is upto and including the `='
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
390 sign. See `sh-feature'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
391 :type '(repeat (cons (symbol :tag "Shell")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
392 (choice regexp
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
393 (cons :format "Evaluate: %v"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
394 (const :format "" eval)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
395 sexp))))
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
396 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
397
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
398
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
399 (defcustom sh-indentation 4
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
400 "The width for further indentation in Shell-Script mode."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
401 :type 'integer
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
402 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
403
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
404
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
405 (defcustom sh-remember-variable-min 3
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
406 "*Don't remember variables less than this length for completing reads."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
407 :type 'integer
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
408 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
409
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
410
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
411 (defvar sh-header-marker nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
412 "When non-`nil' is the end of header for prepending by \\[sh-execute-region].
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
413 That command is also used for setting this variable.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
414
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
415
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
416 (defcustom sh-beginning-of-command
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
417 "\\([;({`|&]\\|\\`\\|[^\\]\n\\)[ \t]*\\([/~a-zA-Z0-9:]\\)"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
418 "*Regexp to determine the beginning of a shell command.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
419 The actual command starts at the beginning of the second \\(grouping\\)."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
420 :type 'regexp
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
421 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
422
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
423
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
424 (defcustom sh-end-of-command
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
425 "\\([/~a-zA-Z0-9:]\\)[ \t]*\\([;#)}`|&]\\|$\\)"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
426 "*Regexp to determine the end of a shell command.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
427 The actual command ends at the end of the first \\(grouping\\)."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
428 :type 'regexp
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
429 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
430
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
431
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
432
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
433 (defvar sh-here-document-word "EOF"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
434 "Word to delimit here documents.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
435
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
436 (defvar sh-test
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
437 '((sh "[ ]" . 2)
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
438 (ksh88 "[[ ]]" . 3))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
439 "Initial input in Bourne if, while and until skeletons. See `sh-feature'.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
440
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
441
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
442 ;; customized this out of sheer bravado. not for the faint of heart.
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
443 ;; but it *did* have an asterisk in the docstring!
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
444 (defcustom sh-builtins
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
445 '((bash eval sh-append posix
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
446 "alias" "bg" "bind" "builtin" "declare" "dirs" "enable" "fc" "fg"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
447 "help" "history" "jobs" "kill" "let" "local" "popd" "pushd" "source"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
448 "suspend" "typeset" "unalias")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
449
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
450 ;; The next entry is only used for defining the others
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
451 (bourne eval sh-append shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
452 "eval" "export" "getopts" "newgrp" "pwd" "read" "readonly"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
453 "times" "ulimit")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
454
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
455 (csh eval sh-append shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
456 "alias" "chdir" "glob" "history" "limit" "nice" "nohup" "rehash"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
457 "setenv" "source" "time" "unalias" "unhash")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
458
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
459 (dtksh eval identity wksh)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
460
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
461 (es "access" "apids" "cd" "echo" "eval" "false" "let" "limit" "local"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
462 "newpgrp" "result" "time" "umask" "var" "vars" "wait" "whatis")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
463
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
464 (jsh eval sh-append sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
465 "bg" "fg" "jobs" "kill" "stop" "suspend")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
466
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
467 (jcsh eval sh-append csh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
468 "bg" "fg" "jobs" "kill" "notify" "stop" "suspend")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
469
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
470 (ksh88 eval sh-append bourne
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
471 "alias" "bg" "false" "fc" "fg" "jobs" "kill" "let" "print" "time"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
472 "typeset" "unalias" "whence")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
473
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
474 (oash eval sh-append sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
475 "checkwin" "dateline" "error" "form" "menu" "newwin" "oadeinit"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
476 "oaed" "oahelp" "oainit" "pp" "ppfile" "scan" "scrollok" "wattr"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
477 "wclear" "werase" "win" "wmclose" "wmmessage" "wmopen" "wmove"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
478 "wmtitle" "wrefresh")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
479
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
480 (pdksh eval sh-append ksh88
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
481 "bind")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
482
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
483 (posix eval sh-append sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
484 "command")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
485
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
486 (rc "builtin" "cd" "echo" "eval" "limit" "newpgrp" "shift" "umask" "wait"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
487 "whatis")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
488
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
489 (sh eval sh-append bourne
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
490 "hash" "test" "type")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
491
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
492 ;; The next entry is only used for defining the others
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
493 (shell "cd" "echo" "eval" "set" "shift" "umask" "unset" "wait")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
494
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
495 (wksh eval sh-append ksh88
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
496 "Xt[A-Z][A-Za-z]*")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
497
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
498 (zsh eval sh-append ksh88
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
499 "autoload" "bindkey" "builtin" "chdir" "compctl" "declare" "dirs"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
500 "disable" "disown" "echotc" "enable" "functions" "getln" "hash"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
501 "history" "integer" "limit" "local" "log" "popd" "pushd" "r"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
502 "readonly" "rehash" "sched" "setopt" "source" "suspend" "true"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
503 "ttyctl" "type" "unfunction" "unhash" "unlimit" "unsetopt" "vared"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
504 "which"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
505 "*List of all shell builtins for completing read and fontification.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
506 Note that on some systems not all builtins are available or some are
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
507 implemented as aliases. See `sh-feature'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
508 :type '(repeat (cons (symbol :tag "Shell")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
509 (choice (repeat string)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
510 (cons :format "Evaluate: %v"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
511 (const :format "" eval)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
512 sexp))))
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
513 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
514
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
515
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
516
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
517 (defcustom sh-leading-keywords
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
518 '((csh "else")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
519
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
520 (es "true" "unwind-protect" "whatis")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
521
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
522 (rc "else")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
523
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
524 (sh "do" "elif" "else" "if" "then" "trap" "type" "until" "while"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
525 "*List of keywords that may be immediately followed by a builtin or keyword.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
526 Given some confusion between keywords and builtins depending on shell and
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
527 system, the distinction here has been based on whether they influence the
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
528 flow of control or syntax. See `sh-feature'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
529 :type '(repeat (cons (symbol :tag "Shell")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
530 (choice (repeat string)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
531 (cons :format "Evaluate: %v"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
532 (const :format "" eval)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
533 sexp))))
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
534 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
535
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
536
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
537 (defcustom sh-other-keywords
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
538 '((bash eval sh-append bourne
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
539 "bye" "logout")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
540
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
541 ;; The next entry is only used for defining the others
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
542 (bourne eval sh-append shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
543 "done" "esac" "fi" "for" "function" "in" "return")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
544
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
545 (csh eval sh-append shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
546 "breaksw" "default" "end" "endif" "endsw" "foreach" "goto"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
547 "if" "logout" "onintr" "repeat" "switch" "then" "while")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
548
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
549 (es "break" "catch" "exec" "exit" "fn" "for" "forever" "fork" "if"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
550 "return" "throw" "while")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
551
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
552 (ksh88 eval sh-append bourne
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
553 "select")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
554
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
555 (rc "break" "case" "exec" "exit" "fn" "for" "if" "in" "return" "switch"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
556 "while")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
557
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
558 ;; The next entry is only used for defining the others
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
559 (shell "break" "case" "continue" "exec" "exit")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
560
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
561 (zsh eval sh-append bash
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
562 "select"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
563 "*List of keywords not in `sh-leading-keywords'.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
564 See `sh-feature'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
565 :type '(repeat (cons (symbol :tag "Shell")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
566 (choice (repeat string)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
567 (cons :format "Evaluate: %v"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
568 (const :format "" eval)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
569 sexp))))
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
570 :group 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
571
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
572
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
573
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
574 (defvar sh-variables
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
575 '((bash eval sh-append sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
576 "allow_null_glob_expansion" "auto_resume" "BASH" "BASH_VERSION"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
577 "cdable_vars" "ENV" "EUID" "FCEDIT" "FIGNORE" "glob_dot_filenames"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
578 "histchars" "HISTFILE" "HISTFILESIZE" "history_control" "HISTSIZE"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
579 "hostname_completion_file" "HOSTTYPE" "IGNOREEOF" "ignoreeof"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
580 "LINENO" "MAIL_WARNING" "noclobber" "nolinks" "notify"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
581 "no_exit_on_failed_exec" "NO_PROMPT_VARS" "OLDPWD" "OPTERR" "PPID"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
582 "PROMPT_COMMAND" "PS4" "pushd_silent" "PWD" "RANDOM" "REPLY"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
583 "SECONDS" "SHLVL" "TMOUT" "UID")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
584
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
585 (csh eval sh-append shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
586 "argv" "cdpath" "child" "echo" "histchars" "history" "home"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
587 "ignoreeof" "mail" "noclobber" "noglob" "nonomatch" "path" "prompt"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
588 "shell" "status" "time" "verbose")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
589
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
590 (es eval sh-append shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
591 "apid" "cdpath" "CDPATH" "history" "home" "ifs" "noexport" "path"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
592 "pid" "prompt" "signals")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
593
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
594 (jcsh eval sh-append csh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
595 "notify")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
596
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
597 (ksh88 eval sh-append sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
598 "ENV" "ERRNO" "FCEDIT" "FPATH" "HISTFILE" "HISTSIZE" "LINENO"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
599 "OLDPWD" "PPID" "PS3" "PS4" "PWD" "RANDOM" "REPLY" "SECONDS"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
600 "TMOUT")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
601
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
602 (oash eval sh-append sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
603 "FIELD" "FIELD_MAX" "LAST_KEY" "OALIB" "PP_ITEM" "PP_NUM")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
604
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
605 (rc eval sh-append shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
606 "apid" "apids" "cdpath" "CDPATH" "history" "home" "ifs" "path" "pid"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
607 "prompt" "status")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
608
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
609 (sh eval sh-append shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
610 "CDPATH" "IFS" "OPTARG" "OPTIND" "PS1" "PS2")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
611
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
612 ;; The next entry is only used for defining the others
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
613 (shell "COLUMNS" "EDITOR" "HOME" "HUSHLOGIN" "LANG" "LC_COLLATE"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
614 "LC_CTYPE" "LC_MESSAGES" "LC_MONETARY" "LC_NUMERIC" "LC_TIME"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
615 "LINES" "LOGNAME" "MAIL" "MAILCHECK" "MAILPATH" "PAGER" "PATH"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
616 "SHELL" "TERM" "TERMCAP" "TERMINFO" "VISUAL")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
617
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
618 (tcsh eval sh-append csh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
619 "addsuffix" "ampm" "autocorrect" "autoexpand" "autolist"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
620 "autologout" "chase_symlinks" "correct" "dextract" "edit" "el"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
621 "fignore" "gid" "histlit" "HOST" "HOSTTYPE" "HPATH"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
622 "ignore_symlinks" "listjobs" "listlinks" "listmax" "matchbeep"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
623 "nobeep" "NOREBIND" "oid" "printexitvalue" "prompt2" "prompt3"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
624 "pushdsilent" "pushdtohome" "recexact" "recognize_only_executables"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
625 "rmstar" "savehist" "SHLVL" "showdots" "sl" "SYSTYPE" "tcsh" "term"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
626 "tperiod" "tty" "uid" "version" "visiblebell" "watch" "who"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
627 "wordchars")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
628
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
629 (zsh eval sh-append ksh88
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
630 "BAUD" "bindcmds" "cdpath" "DIRSTACKSIZE" "fignore" "FIGNORE" "fpath"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
631 "HISTCHARS" "hostcmds" "hosts" "HOSTS" "LISTMAX" "LITHISTSIZE"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
632 "LOGCHECK" "mailpath" "manpath" "NULLCMD" "optcmds" "path" "POSTEDIT"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
633 "prompt" "PROMPT" "PROMPT2" "PROMPT3" "PROMPT4" "psvar" "PSVAR"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
634 "READNULLCMD" "REPORTTIME" "RPROMPT" "RPS1" "SAVEHIST" "SPROMPT"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
635 "STTY" "TIMEFMT" "TMOUT" "TMPPREFIX" "varcmds" "watch" "WATCH"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
636 "WATCHFMT" "WORDCHARS" "ZDOTDIR"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
637 "List of all shell variables available for completing read.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
638 See `sh-feature'.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
639
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
640
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
641
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
642 (defvar sh-font-lock-keywords
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
643 '((csh eval sh-append shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
644 '("\\${?[#?]?\\([A-Za-z_][A-Za-z0-9_]*\\|0\\)" 1
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
645 font-lock-variable-name-face))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
646
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
647 (es eval sh-append executable-font-lock-keywords
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
648 '("\\$#?\\([A-Za-z_][A-Za-z0-9_]*\\|[0-9]+\\)" 1
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
649 font-lock-variable-name-face))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
650
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
651 (rc eval identity es)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
652
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
653 (sh eval sh-append shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
654 '("\\$\\({#?\\)?\\([A-Za-z_][A-Za-z0-9_]*\\|[-#?@!]\\)" 2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
655 font-lock-variable-name-face))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
656
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
657 ;; The next entry is only used for defining the others
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
658 (shell eval sh-append executable-font-lock-keywords
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
659 '("\\\\[^A-Za-z0-9]" 0 font-lock-string-face)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
660 '("\\${?\\([A-Za-z_][A-Za-z0-9_]*\\|[0-9]+\\|[$*_]\\)" 1
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
661 font-lock-variable-name-face)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
662 "*Rules for highlighting shell scripts. See `sh-feature'.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
663
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
664 (defvar sh-font-lock-keywords-1
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
665 '((sh "[ \t]in\\>"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
666 "*Additional rules for highlighting shell scripts. See `sh-feature'.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
667
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
668 (defvar sh-font-lock-keywords-2 ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
669 "*Yet more rules for highlighting shell scripts. See `sh-feature'.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
670
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
671 (defvar sh-font-lock-keywords-only t
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
672 "*Value of `font-lock-keywords-only' for highlighting shell scripts.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
673 Default value is `t' because Emacs' syntax is not expressive enough to
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
674 detect that $# does not start a comment. Thus comments are fontified by
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
675 regexp which means that a single apostrophe in a comment turns everything
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
676 upto the next one or end of buffer into a string.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
677
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
678 ;; mode-command and utility functions
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
679
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
680 ;;;###autoload
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
681 (put 'sh-mode 'mode-class 'special)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
682
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
683 ;;;###autoload
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
684 (defun sh-mode ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
685 "Major mode for editing shell scripts.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
686 This mode works for many shells, since they all have roughly the same syntax,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
687 as far as commands, arguments, variables, pipes, comments etc. are concerned.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
688 Unless the file's magic number indicates the shell, your usual shell is
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
689 assumed. Since filenames rarely give a clue, they are not further analyzed.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
690
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
691 This mode adapts to the variations between shells (see `sh-set-shell') by
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
692 means of an inheritance based feature lookup (see `sh-feature'). This
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
693 mechanism applies to all variables (including skeletons) that pertain to
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
694 shell-specific features.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
695
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
696 The default style of this mode is that of Rosenblatt's Korn shell book.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
697 The syntax of the statements varies with the shell being used. The
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
698 following commands are available, based on the current shell's syntax:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
699
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
700 \\[sh-case] case statement
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
701 \\[sh-for] for loop
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
702 \\[sh-function] function definition
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
703 \\[sh-if] if statement
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
704 \\[sh-indexed-loop] indexed loop from 1 to n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
705 \\[sh-while-getopts] while getopts loop
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
706 \\[sh-repeat] repeat loop
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
707 \\[sh-select] select loop
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
708 \\[sh-until] until loop
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
709 \\[sh-while] while loop
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
710
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
711 \\[backward-delete-char-untabify] Delete backward one position, even if it was a tab.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
712 \\[sh-newline-and-indent] Delete unquoted space and indent new line same as this one.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
713 \\[sh-end-of-command] Go to end of successive commands.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
714 \\[sh-beginning-of-command] Go to beginning of successive commands.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
715 \\[sh-set-shell] Set this buffer's shell, and maybe its magic number.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
716 \\[sh-execute-region] Have optional header and region be executed in a subshell.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
717
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
718 \\[sh-maybe-here-document] Without prefix, following an unquoted < inserts here document.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
719 {, (, [, ', \", `
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
720 Unless quoted with \\, insert the pairs {}, (), [], or '', \"\", ``.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
721
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
722 If you generally program a shell different from your login shell you can
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
723 set `sh-shell-file' accordingly. If your shell's file name doesn't correctly
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
724 indicate what shell it is use `sh-alias-alist' to translate.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
725
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
726 If your shell gives error messages with line numbers, you can use \\[executable-interpret]
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
727 with your script for an edit-interpret-debug cycle."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
728 (interactive)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
729 (kill-all-local-variables)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
730 (use-local-map sh-mode-map)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
731 (make-local-variable 'indent-line-function)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
732 (make-local-variable 'indent-region-function)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
733 (make-local-variable 'skeleton-end-hook)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
734 (make-local-variable 'paragraph-start)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
735 (make-local-variable 'paragraph-separate)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
736 (make-local-variable 'comment-start)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
737 (make-local-variable 'comment-start-skip)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
738 (make-local-variable 'require-final-newline)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
739 (make-local-variable 'sh-header-marker)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
740 (make-local-variable 'sh-shell-file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
741 (make-local-variable 'sh-shell)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
742 (make-local-variable 'skeleton-pair-alist)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
743 (make-local-variable 'skeleton-pair-filter)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
744 (make-local-variable 'comint-dynamic-complete-functions)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
745 (make-local-variable 'comint-prompt-regexp)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
746 (make-local-variable 'font-lock-keywords)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
747 (make-local-variable 'font-lock-defaults)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
748 (make-local-variable 'skeleton-filter)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
749 (make-local-variable 'skeleton-newline-indent-rigidly)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
750 (make-local-variable 'sh-shell-variables)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
751 (make-local-variable 'sh-shell-variables-initialized)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
752 (setq major-mode 'sh-mode
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
753 mode-name "Shell-script"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
754 indent-line-function 'sh-indent-line
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
755 ;; not very clever, but enables wrapping skeletons around regions
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
756 indent-region-function (lambda (b e)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
757 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
758 (goto-char b)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
759 (skip-syntax-backward "-")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
760 (setq b (point))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
761 (goto-char e)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
762 (skip-syntax-backward "-")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
763 (indent-rigidly b (point) sh-indentation)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
764 skeleton-end-hook (lambda ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
765 (or (eolp) (newline) (indent-relative)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
766 paragraph-start (concat page-delimiter "\\|$")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
767 paragraph-separate paragraph-start
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
768 comment-start "# "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
769 comint-dynamic-complete-functions sh-dynamic-complete-functions
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
770 ;; we can't look if previous line ended with `\'
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
771 comint-prompt-regexp "^[ \t]*"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
772 font-lock-defaults
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
773 `((sh-font-lock-keywords
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
774 sh-font-lock-keywords-1
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
775 sh-font-lock-keywords-2)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
776 ,sh-font-lock-keywords-only
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
777 nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
778 ((?/ . "w") (?~ . "w") (?. . "w") (?- . "w") (?_ . "w")))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
779 skeleton-pair-alist '((?` _ ?`))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
780 skeleton-pair-filter 'sh-quoted-p
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
781 skeleton-further-elements '((< '(- (min sh-indentation
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
782 (current-column)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
783 skeleton-filter 'sh-feature
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
784 skeleton-newline-indent-rigidly t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
785 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
786 ;; parse or insert magic number for exec() and set all variables depending
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
787 ;; on the shell thus determined
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
788 (goto-char (point-min))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
789 (and (zerop (buffer-size))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
790 (not buffer-read-only)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
791 (sh-set-shell sh-shell-file)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
792 (run-hooks 'sh-mode-hook))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
793 ;;;###autoload
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
794 (defalias 'shell-script-mode 'sh-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
795
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
796 ;;; XEmacs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
797 (put 'sh-mode 'font-lock-defaults
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
798 `((sh-font-lock-keywords
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
799 sh-font-lock-keywords-1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
800 sh-font-lock-keywords-2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
801 ,sh-font-lock-keywords-only
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
802 nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
803 ((?/ . "w") (?~ . "w") (?. . "w") (?- . "w") (?_ . "w"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
804
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
805
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
806 (defun sh-font-lock-keywords (&optional keywords)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
807 "Function to get simple fontification based on `sh-font-lock-keywords'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
808 This adds rules for comments and assignments."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
809 (sh-feature sh-font-lock-keywords
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
810 (lambda (list)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
811 `((,(concat (sh-feature sh-comment-prefix) "\\(#.*\\)")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
812 2 font-lock-comment-face t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
813 (,(sh-feature sh-assignment-regexp)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
814 1 font-lock-variable-name-face)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
815 ,@keywords
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
816 ,@list))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
817
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
818 (defun sh-font-lock-keywords-1 (&optional builtins)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
819 "Function to get better fontification including keywords."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
820 (let ((keywords (concat "\\([;(){}`|&]\\|^\\)[ \t]*\\(\\(\\("
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
821 (mapconcat 'identity
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
822 (sh-feature sh-leading-keywords)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
823 "\\|")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
824 "\\)[ \t]+\\)?\\("
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
825 (mapconcat 'identity
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
826 (append (sh-feature sh-leading-keywords)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
827 (sh-feature sh-other-keywords))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
828 "\\|")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
829 "\\)")))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
830 (sh-font-lock-keywords
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
831 `(,@(if builtins
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
832 `((,(concat keywords "[ \t]+\\)?\\("
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
833 (mapconcat 'identity (sh-feature sh-builtins) "\\|")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
834 "\\)\\>")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
835 (2 font-lock-keyword-face nil t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
836 (6 font-lock-function-name-face))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
837 ,@(sh-feature sh-font-lock-keywords-2)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
838 (,(concat keywords "\\)\\>")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
839 2 font-lock-keyword-face)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
840 ,@(sh-feature sh-font-lock-keywords-1)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
841
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
842 (defun sh-font-lock-keywords-2 ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
843 "Function to get better fontification including keywords and builtins."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
844 (sh-font-lock-keywords-1 t))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
845
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
846
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
847 (defun sh-set-shell (shell &optional no-query-flag insert-flag)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
848 "Set this buffer's shell to SHELL (a string).
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
849 Makes this script executable via `executable-set-magic'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
850 Calls the value of `sh-set-shell-hook' if set."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
851 (interactive (list (completing-read "Name or path of shell: "
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
852 ;; XEmacs change
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
853 sh-interpreter-mode-alist
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
854 (lambda (x) (eq (cdr x) 'sh-mode)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
855 (eq executable-query 'function)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
856 t))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
857 (setq sh-shell (intern (file-name-nondirectory shell))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
858 sh-shell (or (cdr (assq sh-shell sh-alias-alist))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
859 sh-shell))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
860 (setq sh-shell-file (executable-set-magic shell (sh-feature sh-shell-arg)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
861 (setq require-final-newline (sh-feature sh-require-final-newline)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
862 ;;; local-abbrev-table (sh-feature sh-abbrevs)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
863 font-lock-defaults-computed nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
864 ;; Next two lines kill XEmacs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
865 ;font-lock-keywords nil ; force resetting
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
866 ;font-lock-syntax-table nil
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
867 comment-start-skip (concat (sh-feature sh-comment-prefix) "#+[\t ]*")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
868 mode-line-process (format "[%s]" sh-shell)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
869 sh-shell-variables nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
870 sh-shell-variables-initialized nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
871 shell (sh-feature sh-variables))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
872 (set-syntax-table (sh-feature sh-mode-syntax-table))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
873 (while shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
874 (sh-remember-variable (car shell))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
875 (setq shell (cdr shell)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
876 (and (boundp 'font-lock-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
877 font-lock-mode
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
878 ;; Gnu Emacs, doesn't work
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
879 (font-lock-mode (font-lock-mode 0)))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
880 ;; (font-lock-fontify-buffer))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
881 (run-hooks 'sh-set-shell-hook))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
882
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
883
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
884
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
885 (defun sh-feature (list &optional function)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
886 "Index ALIST by the current shell.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
887 If ALIST isn't a list where every element is a cons, it is returned as is.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
888 Else indexing follows an inheritance logic which works in two ways:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
889
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
890 - Fall back on successive ancestors (see `sh-ancestor-alist') as long as
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
891 the alist contains no value for the current shell.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
892
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
893 - If the value thus looked up is a list starting with `eval' its `cdr' is
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
894 first evaluated. If that is also a list and the first argument is a
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
895 symbol in ALIST it is not evaluated, but rather recursively looked up in
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
896 ALIST to allow the function called to define the value for one shell to be
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
897 derived from another shell. While calling the function, is the car of the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
898 alist element is the current shell.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
899 The value thus determined is physically replaced into the alist.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
900
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
901 Optional FUNCTION is applied to the determined value and the result is cached
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
902 in ALIST."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
903 (or (if (consp list)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
904 (let ((l list))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
905 (while (and l (consp (car l)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
906 (setq l (cdr l)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
907 (if l list)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
908 (if function
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
909 (cdr (assoc (setq function (cons sh-shell function)) list)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
910 (let ((sh-shell sh-shell)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
911 elt val)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
912 (while (and sh-shell
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
913 (not (setq elt (assq sh-shell list))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
914 (setq sh-shell (cdr (assq sh-shell sh-ancestor-alist))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
915 (if (and (consp (setq val (cdr elt)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
916 (eq (car val) 'eval))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
917 (setcdr elt
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
918 (setq val
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
919 (eval (if (consp (setq val (cdr val)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
920 (let ((sh-shell (car (cdr val)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
921 function)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
922 (if (assq sh-shell list)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
923 (setcar (cdr val)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
924 (list 'quote
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
925 (sh-feature list))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
926 val)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
927 val)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
928 (if function
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
929 (nconc list
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
930 (list (cons function
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
931 (setq sh-shell (car function)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
932 val (funcall (cdr function) val))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
933 val)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
934
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
935
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
936
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
937 ;;; I commented this out because nobody calls it -- rms.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
938 ;;;(defun sh-abbrevs (ancestor &rest list)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
939 ;;; "Iff it isn't, define the current shell as abbrev table and fill that.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
940 ;;;Abbrev table will inherit all abbrevs from ANCESTOR, which is either an abbrev
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
941 ;;;table or a list of (NAME1 EXPANSION1 ...). In addition it will define abbrevs
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
942 ;;;according to the remaining arguments NAMEi EXPANSIONi ...
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
943 ;;;EXPANSION may be either a string or a skeleton command."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
944 ;;; (or (if (boundp sh-shell)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
945 ;;; (symbol-value sh-shell))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
946 ;;; (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
947 ;;; (if (listp ancestor)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
948 ;;; (nconc list ancestor))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
949 ;;; (define-abbrev-table sh-shell ())
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
950 ;;; (if (vectorp ancestor)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
951 ;;; (mapatoms (lambda (atom)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
952 ;;; (or (eq atom 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
953 ;;; (define-abbrev (symbol-value sh-shell)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
954 ;;; (symbol-name atom)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
955 ;;; (symbol-value atom)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
956 ;;; (symbol-function atom))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
957 ;;; ancestor))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
958 ;;; (while list
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
959 ;;; (define-abbrev (symbol-value sh-shell)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
960 ;;; (car list)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
961 ;;; (if (stringp (car (cdr list)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
962 ;;; (car (cdr list))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
963 ;;; "")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
964 ;;; (if (symbolp (car (cdr list)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
965 ;;; (car (cdr list))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
966 ;;; (setq list (cdr (cdr list)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
967 ;;; (symbol-value sh-shell)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
968
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
969
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
970 (defun sh-mode-syntax-table (table &rest list)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
971 "Copy TABLE and set syntax for successive CHARs according to strings S."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
972 (setq table (copy-syntax-table table))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
973 (while list
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
974 (modify-syntax-entry (car list) (car (cdr list)) table)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
975 (setq list (cdr (cdr list))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
976 table)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
977
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
978
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
979 (defun sh-append (ancestor &rest list)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
980 "Return list composed of first argument (a list) physically appended to rest."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
981 (nconc list ancestor))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
982
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
983
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
984 (defun sh-modify (skeleton &rest list)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
985 "Modify a copy of SKELETON by replacing I1 with REPL1, I2 with REPL2 ..."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
986 (setq skeleton (copy-sequence skeleton))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
987 (while list
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
988 (setcar (or (nthcdr (car list) skeleton)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
989 (error "Index %d out of bounds" (car list)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
990 (car (cdr list)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
991 (setq list (nthcdr 2 list)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
992 skeleton)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
993
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
994
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
995 (defun sh-indent-line ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
996 "Indent as far as preceding non-empty line, then by steps of `sh-indentation'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
997 Lines containing only comments are considered empty."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
998 (interactive)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
999 (let ((previous (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1000 (while (and (not (bobp))
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 120
diff changeset
1001 (not (eq (point-min) (point-at-bol)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1002 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1003 (forward-line -1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1004 (back-to-indentation)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1005 (or (eolp)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1006 (eq (following-char) ?#)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1007 (current-column)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1008 current)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1009 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1010 (indent-to (if (eq this-command 'newline-and-indent)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1011 previous
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1012 (if (< (current-column)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1013 (setq current (progn (back-to-indentation)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1014 (current-column))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1015 (if (eolp) previous 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1016 (delete-region (point)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1017 (progn (beginning-of-line) (point)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1018 (if (eolp)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1019 (max previous (* (1+ (/ current sh-indentation))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1020 sh-indentation))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1021 (* (1+ (/ current sh-indentation)) sh-indentation))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1022 (if (< (current-column) (current-indentation))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1023 (skip-chars-forward " \t"))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1024
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1025
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1026 (defun sh-execute-region (start end &optional flag)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1027 "Pass optional header and region to a subshell for noninteractive execution.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1028 The working directory is that of the buffer, and only environment variables
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1029 are already set which is why you can mark a header within the script.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1030
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1031 With a positive prefix ARG, instead of sending region, define header from
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1032 beginning of buffer to point. With a negative prefix ARG, instead of sending
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1033 region, clear header."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1034 (interactive "r\nP")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1035 (if flag
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1036 (setq sh-header-marker (if (> (prefix-numeric-value flag) 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1037 (point-marker)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1038 (if sh-header-marker
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1039 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1040 (let (buffer-undo-list)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1041 (goto-char sh-header-marker)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1042 (append-to-buffer (current-buffer) start end)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1043 (shell-command-on-region (point-min)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1044 (setq end (+ sh-header-marker
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1045 (- end start)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1046 sh-shell-file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1047 (delete-region sh-header-marker end)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1048 (shell-command-on-region start end (concat sh-shell-file " -")))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1049
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1050
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1051 (defun sh-remember-variable (var)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1052 "Make VARIABLE available for future completing reads in this buffer."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1053 (or (< (length var) sh-remember-variable-min)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1054 (getenv var)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1055 (assoc var sh-shell-variables)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1056 (setq sh-shell-variables (cons (cons var var) sh-shell-variables)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1057 var)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1058
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1059
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1060
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1061 (defun sh-quoted-p ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1062 "Is point preceded by an odd number of backslashes?"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1063 (eq -1 (% (save-excursion (skip-chars-backward "\\\\")) 2)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1064
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1065 ;; statement syntax-commands for various shells
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1066
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1067 ;; You are welcome to add the syntax or even completely new statements as
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1068 ;; appropriate for your favorite shell.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1069
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1070 (define-skeleton sh-case
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1071 "Insert a case/switch statement. See `sh-feature'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1072 (csh "expression: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1073 "switch( " str " )" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1074 > "case " (read-string "pattern: ") ?: \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1075 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1076 "breaksw" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1077 ( "other pattern, %s: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1078 < "case " str ?: \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1079 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1080 "breaksw" \n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1081 < "default:" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1082 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1083 resume:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1084 < < "endsw")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1085 (es)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1086 (rc "expression: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1087 "switch( " str " ) {" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1088 > "case " (read-string "pattern: ") \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1089 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1090 ( "other pattern, %s: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1091 < "case " str \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1092 > _ \n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1093 < "case *" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1094 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1095 resume:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1096 < < ?})
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1097 (sh "expression: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1098 "case " str " in" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1099 > (read-string "pattern: ") ?\) \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1100 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1101 ";;" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1102 ( "other pattern, %s: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1103 < str ?\) \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1104 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1105 ";;" \n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1106 < "*)" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1107 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1108 resume:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1109 < < "esac"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1110 (put 'sh-case 'menu-enable '(sh-feature sh-case))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1111
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1112
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1113
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1114 (define-skeleton sh-for
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1115 "Insert a for loop. See `sh-feature'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1116 (csh eval sh-modify sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1117 1 "foreach "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1118 3 " ( "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1119 5 " )"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1120 15 "end")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1121 (es eval sh-modify rc
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1122 3 " = ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1123 (rc eval sh-modify sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1124 1 "for( "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1125 5 " ) {"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1126 15 ?})
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1127 (sh "Index variable: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1128 "for " str " in " _ "; do" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1129 > _ | ?$ & (sh-remember-variable str) \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1130 < "done"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1131
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1132
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1133
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1134 (define-skeleton sh-indexed-loop
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1135 "Insert an indexed loop from 1 to n. See `sh-feature'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1136 (bash eval identity posix)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1137 (csh "Index variable: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1138 "@ " str " = 1" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1139 "while( $" str " <= " (read-string "upper limit: ") " )" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1140 > _ ?$ str \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1141 "@ " str "++" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1142 < "end")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1143 (es eval sh-modify rc
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1144 3 " =")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1145 (ksh88 "Index variable: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1146 "integer " str "=0" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1147 "while (( ( " str " += 1 ) <= "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1148 (read-string "upper limit: ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1149 " )); do" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1150 > _ ?$ (sh-remember-variable str) \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1151 < "done")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1152 (posix "Index variable: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1153 str "=1" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1154 "while [ $" str " -le "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1155 (read-string "upper limit: ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1156 " ]; do" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1157 > _ ?$ str \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1158 str ?= (sh-add (sh-remember-variable str) 1) \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1159 < "done")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1160 (rc "Index variable: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1161 "for( " str " in" " `{awk 'BEGIN { for( i=1; i<="
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1162 (read-string "upper limit: ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1163 "; i++ ) print i }'}) {" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1164 > _ ?$ (sh-remember-variable str) \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1165 < ?})
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1166 (sh "Index variable: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1167 "for " str " in `awk 'BEGIN { for( i=1; i<="
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1168 (read-string "upper limit: ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1169 "; i++ ) print i }'`; do" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1170 > _ ?$ (sh-remember-variable str) \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1171 < "done"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1172
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1173
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1174 (defun sh-shell-initialize-variables ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1175 "Scan the buffer for variable assignments.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1176 Add these variables to `sh-shell-variables'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1177 (message "Scanning buffer `%s' for variable assignments..." (buffer-name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1178 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1179 (goto-char (point-min))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1180 (setq sh-shell-variables-initialized t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1181 (while (search-forward "=" nil t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1182 (sh-assignment 0)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1183 (message "Scanning buffer `%s' for variable assignments...done"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1184 (buffer-name)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1185
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1186 (defvar sh-add-buffer)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1187
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1188 (defun sh-add-completer (string predicate code)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1189 "Do completion using `sh-shell-variables', but initialize it first.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1190 This function is designed for use as the \"completion table\",
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1191 so it takes three arguments:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1192 STRING, the current buffer contents;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1193 PREDICATE, the predicate for filtering possible matches;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1194 CODE, which says what kind of things to do.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1195 CODE can be nil, t or `lambda'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1196 nil means to return the best completion of STRING, or nil if there is none.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1197 t means to return a list of all possible completions of STRING.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1198 `lambda' means to return t if STRING is a valid completion as it stands."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1199 (let ((sh-shell-variables
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1200 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1201 (set-buffer sh-add-buffer)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1202 (or sh-shell-variables-initialized
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1203 (sh-shell-initialize-variables))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1204 (nconc (mapcar (lambda (var)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1205 (let ((name
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1206 (substring var 0 (string-match "=" var))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1207 (cons name name)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1208 process-environment)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1209 sh-shell-variables))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1210 (cond ((null code)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1211 (try-completion string sh-shell-variables predicate))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1212 ((eq code t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1213 (all-completions string sh-shell-variables predicate))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1214 ((eq code 'lambda)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1215 (assoc string sh-shell-variables)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1216
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1217 (defun sh-add (var delta)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1218 "Insert an addition of VAR and prefix DELTA for Bourne (type) shell."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1219 (interactive
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1220 (let ((sh-add-buffer (current-buffer)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1221 (list (completing-read "Variable: " 'sh-add-completer)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1222 (prefix-numeric-value current-prefix-arg))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1223 (insert (sh-feature '((bash . "$[ ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1224 (ksh88 . "$(( ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1225 (posix . "$(( ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1226 (rc . "`{expr $")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1227 (sh . "`expr $")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1228 (zsh . "$[ ")))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1229 (sh-remember-variable var)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1230 (if (< delta 0) " - " " + ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1231 (number-to-string (abs delta))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1232 (sh-feature '((bash . " ]")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1233 (ksh88 . " ))")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1234 (posix . " ))")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1235 (rc . "}")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1236 (sh . "`")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1237 (zsh . " ]")))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1238
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1239
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1240
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1241 (define-skeleton sh-function
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1242 "Insert a function definition. See `sh-feature'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1243 (bash eval sh-modify ksh88
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1244 3 "() {")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1245 (ksh88 "name: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1246 "function " str " {" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1247 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1248 < "}")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1249 (rc eval sh-modify ksh88
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1250 1 "fn ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1251 (sh ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1252 "() {" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1253 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1254 < "}"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1255
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1256
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1257
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1258 (define-skeleton sh-if
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1259 "Insert an if statement. See `sh-feature'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1260 (csh "condition: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1261 "if( " str " ) then" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1262 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1263 ( "other condition, %s: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1264 < "else if( " str " ) then" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1265 > _ \n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1266 < "else" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1267 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1268 resume:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1269 < "endif")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1270 (es "condition: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1271 "if { " str " } {" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1272 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1273 ( "other condition, %s: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1274 < "} { " str " } {" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1275 > _ \n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1276 < "} {" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1277 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1278 resume:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1279 < ?})
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1280 (rc eval sh-modify csh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1281 3 " ) {"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1282 8 '( "other condition, %s: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1283 < "} else if( " str " ) {" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1284 > _ \n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1285 10 "} else {"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1286 17 ?})
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1287 (sh "condition: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1288 '(setq input (sh-feature sh-test))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1289 "if " str "; then" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1290 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1291 ( "other condition, %s: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1292 < "elif " str "; then" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1293 > _ \n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1294 < "else" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1295 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1296 resume:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1297 < "fi"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1298
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1299
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1300
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1301 (define-skeleton sh-repeat
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1302 "Insert a repeat loop definition. See `sh-feature'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1303 (es nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1304 "forever {" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1305 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1306 < ?})
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1307 (zsh "factor: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1308 "repeat " str "; do"\n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1309 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1310 < "done"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1311 (put 'sh-repeat 'menu-enable '(sh-feature sh-repeat))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1312
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1313
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1314
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1315 (define-skeleton sh-select
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1316 "Insert a select statement. See `sh-feature'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1317 (ksh88 "Index variable: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1318 "select " str " in " _ "; do" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1319 > ?$ str \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1320 < "done"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1321 (put 'sh-select 'menu-enable '(sh-feature sh-select))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1322
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1323
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1324
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1325 (define-skeleton sh-tmp-file
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1326 "Insert code to setup temporary file handling. See `sh-feature'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1327 (bash eval identity ksh88)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1328 (csh (file-name-nondirectory (buffer-file-name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1329 "set tmp = /tmp/" str ".$$" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1330 "onintr exit" \n _
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1331 (and (goto-char (point-max))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1332 (not (bolp))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1333 ?\n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1334 "exit:\n"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1335 "rm $tmp* >&/dev/null" >)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1336 (es (file-name-nondirectory (buffer-file-name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1337 "local( signals = $signals sighup sigint; tmp = /tmp/" str ".$pid ) {" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1338 > "catch @ e {" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1339 > "rm $tmp^* >[2]/dev/null" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1340 "throw $e" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1341 < "} {" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1342 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1343 < ?} \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1344 < ?})
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1345 (ksh88 eval sh-modify sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1346 6 "EXIT")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1347 (rc (file-name-nondirectory (buffer-file-name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1348 "tmp = /tmp/" str ".$pid" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1349 "fn sigexit { rm $tmp^* >[2]/dev/null }")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1350 (sh (file-name-nondirectory (buffer-file-name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1351 "TMP=/tmp/" str ".$$" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1352 "trap \"rm $TMP* 2>/dev/null\" " ?0))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1353
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1354
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1355
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1356 (define-skeleton sh-until
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1357 "Insert an until loop. See `sh-feature'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1358 (sh "condition: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1359 '(setq input (sh-feature sh-test))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1360 "until " str "; do" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1361 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1362 < "done"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1363 (put 'sh-until 'menu-enable '(sh-feature sh-until))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1364
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1365
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1366
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1367 (define-skeleton sh-while
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1368 "Insert a while loop. See `sh-feature'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1369 (csh eval sh-modify sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1370 2 "while( "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1371 4 " )"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1372 10 "end")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1373 (es eval sh-modify rc
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1374 2 "while { "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1375 4 " } {")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1376 (rc eval sh-modify csh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1377 4 " ) {"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1378 10 ?})
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1379 (sh "condition: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1380 '(setq input (sh-feature sh-test))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1381 "while " str "; do" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1382 > _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1383 < "done"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1384
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1385
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1386
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1387 (define-skeleton sh-while-getopts
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1388 "Insert a while getopts loop. See `sh-feature'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1389 Prompts for an options string which consists of letters for each recognized
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1390 option followed by a colon `:' if the option accepts an argument."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1391 (bash eval sh-modify sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1392 18 "${0##*/}")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1393 (csh nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1394 "while( 1 )" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1395 > "switch( \"$1\" )" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1396 '(setq input '("- x" . 2))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1397 > >
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1398 ( "option, %s: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1399 < "case " '(eval str)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1400 '(if (string-match " +" str)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1401 (setq v1 (substring str (match-end 0))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1402 str (substring str 0 (match-beginning 0)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1403 (setq v1 nil))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1404 str ?: \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1405 > "set " v1 & " = $2" | -4 & _ \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1406 (if v1 "shift") & \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1407 "breaksw" \n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1408 < "case --:" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1409 > "shift" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1410 < "default:" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1411 > "break" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1412 resume:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1413 < < "endsw" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1414 "shift" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1415 < "end")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1416 (ksh88 eval sh-modify sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1417 16 "print"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1418 18 "${0##*/}"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1419 36 "OPTIND-1")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1420 (posix eval sh-modify sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1421 18 "$(basename $0)")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1422 (sh "optstring: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1423 "while getopts :" str " OPT; do" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1424 > "case $OPT in" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1425 > >
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1426 '(setq v1 (append (vconcat str) nil))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1427 ( (prog1 (if v1 (char-to-string (car v1)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1428 (if (eq (nth 1 v1) ?:)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1429 (setq v1 (nthcdr 2 v1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1430 v2 "\"$OPTARG\"")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1431 (setq v1 (cdr v1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1432 v2 nil)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1433 < str "|+" str ?\) \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1434 > _ v2 \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1435 ";;" \n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1436 < "*)" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1437 > "echo" " \"usage: " "`basename $0`"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1438 " [+-" '(setq v1 (point)) str
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1439 '(save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1440 (while (search-backward ":" v1 t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1441 (replace-match " ARG] [+-" t t)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1442 (if (eq (preceding-char) ?-) -5)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1443 "] [--] ARGS...\"" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1444 "exit 2" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1445 < < "esac" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1446 < "done" \n
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1447 "shift " (sh-add "OPTIND" -1)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1448 (put 'sh-while-getopts 'menu-enable '(sh-feature sh-while-getopts))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1449
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1450
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1451
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1452 (defun sh-assignment (arg)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1453 "Remember preceding identifier for future completion and do self-insert."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1454 (interactive "p")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1455 (self-insert-command arg)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1456 (if (<= arg 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1457 (sh-remember-variable
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1458 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1459 (if (re-search-forward (sh-feature sh-assignment-regexp)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1460 (prog1 (point)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1461 (beginning-of-line 1))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1462 t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1463 (match-string 1))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1464
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1465
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1466
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1467 (defun sh-maybe-here-document (arg)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1468 "Inserts self. Without prefix, following unquoted `<' inserts here document.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1469 The document is bounded by `sh-here-document-word'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1470 (interactive "*P")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1471 (self-insert-command (prefix-numeric-value arg))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1472 (or arg
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1473 (not (eq (char-after (- (point) 2)) last-command-char))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1474 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1475 (backward-char 2)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1476 (sh-quoted-p))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1477 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1478 (insert sh-here-document-word)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1479 (or (eolp) (looking-at "[ \t]") (insert ? ))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1480 (end-of-line 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1481 (while
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1482 (sh-quoted-p)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1483 (end-of-line 2))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1484 (newline)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1485 (save-excursion (insert ?\n sh-here-document-word)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1486
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1487
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1488 ;; various other commands
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1489
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1490 (autoload 'comint-dynamic-complete "comint"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1491 "Dynamically perform completion at point." t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1492
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1493 (autoload 'shell-dynamic-complete-command "shell"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1494 "Dynamically complete the command at point." t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1495
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1496 (autoload 'comint-dynamic-complete-filename "comint"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1497 "Dynamically complete the filename at point." t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1498
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1499 (autoload 'shell-dynamic-complete-environment-variable "shell"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1500 "Dynamically complete the environment variable at point." t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1501
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1502
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1503
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1504 (defun sh-newline-and-indent ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1505 "Strip unquoted whitespace, insert newline, and indent like current line."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1506 (interactive "*")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1507 (indent-to (prog1 (current-indentation)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1508 (delete-region (point)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1509 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1510 (or (zerop (skip-chars-backward " \t"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1511 (if (sh-quoted-p)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1512 (forward-char)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1513 (point)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1514 (newline))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1515
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1516
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1517
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1518 (defun sh-beginning-of-command ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1519 "Move point to successive beginnings of commands."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1520 (interactive)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1521 (if (re-search-backward sh-beginning-of-command nil t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1522 (goto-char (match-beginning 2))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1523
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1524
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1525 (defun sh-end-of-command ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1526 "Move point to successive ends of commands."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1527 (interactive)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1528 (if (re-search-forward sh-end-of-command nil t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1529 (goto-char (match-end 1))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1530
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 153
diff changeset
1531 (provide 'sh)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1532 ;; sh-script.el ends here
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1533