annotate lisp/modes/sh-script.el @ 104:cf808b4c4290 r20-1b4

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