annotate lisp/modes/sh-script.el @ 131:869e1851236b xemacs-20-1p4

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