annotate lisp/modes/sh-script.el @ 153:25f70ba0133c r20-3b3

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