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