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