comparison lisp/progmodes/sh-script.el @ 40335:96186171af6d

no functional changes - a preparation for the next patch
author Sam Steingold <sds@gnu.org>
date Fri, 26 Oct 2001 13:48:53 +0000
parents bc9296467c86
children 8f116e4bd2cd
comparison
equal deleted inserted replaced
40334:bee6cc2e8a90 40335:96186171af6d
41 41
42 ;; Indentation 42 ;; Indentation
43 ;; =========== 43 ;; ===========
44 ;; Indentation for rc and es modes is very limited, but for Bourne shells 44 ;; Indentation for rc and es modes is very limited, but for Bourne shells
45 ;; and its derivatives it is quite customizable. 45 ;; and its derivatives it is quite customizable.
46 ;; 46 ;;
47 ;; The following description applies to sh and derived shells (bash, 47 ;; The following description applies to sh and derived shells (bash,
48 ;; zsh, ...). 48 ;; zsh, ...).
49 ;; 49 ;;
50 ;; There are various customization variables which allow tailoring to 50 ;; There are various customization variables which allow tailoring to
51 ;; a wide variety of styles. Most of these variables are named 51 ;; a wide variety of styles. Most of these variables are named
52 ;; sh-indent-for-XXX and sh-indent-after-XXX. For example. 52 ;; sh-indent-for-XXX and sh-indent-after-XXX. For example.
53 ;; sh-indent-after-if controls the indenting of a line following 53 ;; sh-indent-after-if controls the indenting of a line following
54 ;; an if statement, and sh-indent-for-fi controls the indentation 54 ;; an if statement, and sh-indent-for-fi controls the indentation
55 ;; of the line containing the fi. 55 ;; of the line containing the fi.
56 ;; 56 ;;
57 ;; You can set each to a numeric value, but it is often more convenient 57 ;; You can set each to a numeric value, but it is often more convenient
58 ;; to a symbol such as `+' which uses the value of variable `sh-basic-offset'. 58 ;; to a symbol such as `+' which uses the value of variable `sh-basic-offset'.
59 ;; By changing this one variable you can increase or decrease how much 59 ;; By changing this one variable you can increase or decrease how much
60 ;; indentation there is. Valid symbols: 60 ;; indentation there is. Valid symbols:
61 ;; 61 ;;
62 ;; + Indent right by sh-basic-offset 62 ;; + Indent right by sh-basic-offset
63 ;; - Indent left by sh-basic-offset 63 ;; - Indent left by sh-basic-offset
64 ;; ++ Indent right twice sh-basic-offset 64 ;; ++ Indent right twice sh-basic-offset
65 ;; -- Indent left twice sh-basic-offset 65 ;; -- Indent left twice sh-basic-offset
66 ;; * Indent right half sh-basic-offset 66 ;; * Indent right half sh-basic-offset
67 ;; / Indent left half sh-basic-offset. 67 ;; / Indent left half sh-basic-offset.
68 ;; 68 ;;
69 ;; There are 4 commands to help set the indentation variables: 69 ;; There are 4 commands to help set the indentation variables:
70 ;; 70 ;;
71 ;; `sh-show-indent' 71 ;; `sh-show-indent'
72 ;; This shows what variable controls the indentation of the current 72 ;; This shows what variable controls the indentation of the current
73 ;; line and its value. 73 ;; line and its value.
74 ;; 74 ;;
75 ;; `sh-set-indent' 75 ;; `sh-set-indent'
76 ;; This allows you to set the value of the variable controlling the 76 ;; This allows you to set the value of the variable controlling the
77 ;; current line's indentation. You can enter a number or one of a 77 ;; current line's indentation. You can enter a number or one of a
78 ;; number of special symbols to denote the value of sh-basic-offset, 78 ;; number of special symbols to denote the value of sh-basic-offset,
79 ;; or its negative, or half it, or twice it, etc. If you've used 79 ;; or its negative, or half it, or twice it, etc. If you've used
80 ;; cc-mode this should be familiar. If you forget which symbols are 80 ;; cc-mode this should be familiar. If you forget which symbols are
81 ;; valid simply press C-h at the prompt. 81 ;; valid simply press C-h at the prompt.
82 ;; 82 ;;
83 ;; `sh-learn-line-indent' 83 ;; `sh-learn-line-indent'
84 ;; Simply make the line look the way you want it, then invoke this 84 ;; Simply make the line look the way you want it, then invoke this
85 ;; command. It will set the variable to the value that makes the line 85 ;; command. It will set the variable to the value that makes the line
86 ;; indent like that. If called with a prefix argument then it will set 86 ;; indent like that. If called with a prefix argument then it will set
87 ;; the value to one of the symbols if applicable. 87 ;; the value to one of the symbols if applicable.
88 ;; 88 ;;
89 ;; `sh-learn-buffer-indent' 89 ;; `sh-learn-buffer-indent'
90 ;; This is the deluxe function! It "learns" the whole buffer (use 90 ;; This is the deluxe function! It "learns" the whole buffer (use
91 ;; narrowing if you want it to process only part). It outputs to a 91 ;; narrowing if you want it to process only part). It outputs to a
92 ;; buffer *indent* any conflicts it finds, and all the variables it has 92 ;; buffer *indent* any conflicts it finds, and all the variables it has
93 ;; learned. This buffer is a sort of Occur mode buffer, allowing you to 93 ;; learned. This buffer is a sort of Occur mode buffer, allowing you to
96 ;; non-nil. 96 ;; non-nil.
97 ;; `sh-indent-comment' will be set if all comments follow the same 97 ;; `sh-indent-comment' will be set if all comments follow the same
98 ;; pattern; if they don't it will be set to nil. 98 ;; pattern; if they don't it will be set to nil.
99 ;; Whether `sh-basic-offset' is set is determined by variable 99 ;; Whether `sh-basic-offset' is set is determined by variable
100 ;; `sh-learn-basic-offset'. 100 ;; `sh-learn-basic-offset'.
101 ;; 101 ;;
102 ;; Unfortunately, `sh-learn-buffer-indent' can take a long time to run 102 ;; Unfortunately, `sh-learn-buffer-indent' can take a long time to run
103 ;; (e.g. if there are large case statements). Perhaps it does not make 103 ;; (e.g. if there are large case statements). Perhaps it does not make
104 ;; sense to run it on large buffers: if lots of lines have different 104 ;; sense to run it on large buffers: if lots of lines have different
105 ;; indentation styles it will produce a lot of diagnostics in the 105 ;; indentation styles it will produce a lot of diagnostics in the
106 ;; *indent* buffer; if there is a consistent style then running 106 ;; *indent* buffer; if there is a consistent style then running
107 ;; `sh-learn-buffer-indent' on a small region of the buffer should 107 ;; `sh-learn-buffer-indent' on a small region of the buffer should
108 ;; suffice. 108 ;; suffice.
109 ;; 109 ;;
110 ;; Saving indentation values 110 ;; Saving indentation values
111 ;; ------------------------- 111 ;; -------------------------
112 ;; After you've learned the values in a buffer, how to you remember 112 ;; After you've learned the values in a buffer, how to you remember
113 ;; them? Originally I had hoped that `sh-learn-buffer-indent' 113 ;; them? Originally I had hoped that `sh-learn-buffer-indent'
114 ;; would make this unnecessary; simply learn the values when you visit 114 ;; would make this unnecessary; simply learn the values when you visit
115 ;; the buffer. 115 ;; the buffer.
116 ;; You can do this automatically like this: 116 ;; You can do this automatically like this:
117 ;; (add-hook 'sh-set-shell-hook 'sh-learn-buffer-indent) 117 ;; (add-hook 'sh-set-shell-hook 'sh-learn-buffer-indent)
118 ;; 118 ;;
119 ;; However... `sh-learn-buffer-indent' is extremely slow, 119 ;; However... `sh-learn-buffer-indent' is extremely slow,
120 ;; especially on large-ish buffer. Also, if there are conflicts the 120 ;; especially on large-ish buffer. Also, if there are conflicts the
121 ;; "last one wins" which may not produce the desired setting. 121 ;; "last one wins" which may not produce the desired setting.
122 ;; 122 ;;
123 ;; So...There is a minimal way of being able to save indentation values and 123 ;; So...There is a minimal way of being able to save indentation values and
124 ;; to reload them in another buffer or at another point in time. 124 ;; to reload them in another buffer or at another point in time.
125 ;; 125 ;;
126 ;; Use `sh-name-style' to give a name to the indentation settings of 126 ;; Use `sh-name-style' to give a name to the indentation settings of
127 ;; the current buffer. 127 ;; the current buffer.
128 ;; Use `sh-load-style' to load indentation settings for the current 128 ;; Use `sh-load-style' to load indentation settings for the current
129 ;; buffer from a specific style. 129 ;; buffer from a specific style.
130 ;; Use `sh-save-styles-to-buffer' to write all the styles to a buffer 130 ;; Use `sh-save-styles-to-buffer' to write all the styles to a buffer
131 ;; in lisp code. You can then store it in a file and later use 131 ;; in lisp code. You can then store it in a file and later use
132 ;; `load-file' to load it. 132 ;; `load-file' to load it.
133 ;; 133 ;;
134 ;; Indentation variables - buffer local or global? 134 ;; Indentation variables - buffer local or global?
135 ;; ---------------------------------------------- 135 ;; ----------------------------------------------
136 ;; I think that often having them buffer-local makes sense, 136 ;; I think that often having them buffer-local makes sense,
137 ;; especially if one is using `sh-learn-buffer-indent'. However, if 137 ;; especially if one is using `sh-learn-buffer-indent'. However, if
138 ;; a user sets values using customization, these changes won't appear 138 ;; a user sets values using customization, these changes won't appear
139 ;; to work if the variables are already local! 139 ;; to work if the variables are already local!
140 ;; 140 ;;
141 ;; To get round this, there is a variable `sh-make-vars-local' and 2 141 ;; To get round this, there is a variable `sh-make-vars-local' and 2
142 ;; functions: `sh-make-vars-local' and `sh-reset-indent-vars-to-global-values'. 142 ;; functions: `sh-make-vars-local' and `sh-reset-indent-vars-to-global-values'.
143 ;; 143 ;;
144 ;; If `sh-make-vars-local' is non-nil, then these variables become 144 ;; If `sh-make-vars-local' is non-nil, then these variables become
145 ;; buffer local when the mode is established. 145 ;; buffer local when the mode is established.
146 ;; If this is nil, then the variables are global. At any time you 146 ;; If this is nil, then the variables are global. At any time you
147 ;; can make them local with the command `sh-make-vars-local'. 147 ;; can make them local with the command `sh-make-vars-local'.
148 ;; Conversely, to update with the global values you can use the 148 ;; Conversely, to update with the global values you can use the
149 ;; command `sh-reset-indent-vars-to-global-values'. 149 ;; command `sh-reset-indent-vars-to-global-values'.
150 ;; 150 ;;
151 ;; This may be awkward, but the intent is to cover all cases. 151 ;; This may be awkward, but the intent is to cover all cases.
152 ;; 152 ;;
153 ;; Awkward things, pitfalls 153 ;; Awkward things, pitfalls
154 ;; ------------------------ 154 ;; ------------------------
155 ;; Indentation for a sh script is complicated for a number of reasons: 155 ;; Indentation for a sh script is complicated for a number of reasons:
156 ;; 156 ;;
157 ;; 1. You can't format by simply looking at symbols, you need to look 157 ;; 1. You can't format by simply looking at symbols, you need to look
158 ;; at keywords. [This is not the case for rc and es shells.] 158 ;; at keywords. [This is not the case for rc and es shells.]
159 ;; 2. The character ")" is used both as a matched pair "(" ... ")" and 159 ;; 2. The character ")" is used both as a matched pair "(" ... ")" and
160 ;; as a stand-alone symbol (in a case alternative). This makes 160 ;; as a stand-alone symbol (in a case alternative). This makes
161 ;; things quite tricky! 161 ;; things quite tricky!
163 ;; they terminate we want to revert to the indentation of the line 163 ;; they terminate we want to revert to the indentation of the line
164 ;; containing the "<<" symbol. 164 ;; containing the "<<" symbol.
165 ;; 4. A line may be continued using the "\". 165 ;; 4. A line may be continued using the "\".
166 ;; 5. The character "#" (outside a string) normally starts a comment, 166 ;; 5. The character "#" (outside a string) normally starts a comment,
167 ;; but it doesn't in the sequence "$#"! 167 ;; but it doesn't in the sequence "$#"!
168 ;; 168 ;;
169 ;; To try and address points 2 3 and 5 I used a feature that cperl mode 169 ;; To try and address points 2 3 and 5 I used a feature that cperl mode
170 ;; uses, that of a text's syntax property. This, however, has 2 170 ;; uses, that of a text's syntax property. This, however, has 2
171 ;; disadvantages: 171 ;; disadvantages:
172 ;; 1. We need to scan the buffer to find which ")" symbols belong to a 172 ;; 1. We need to scan the buffer to find which ")" symbols belong to a
173 ;; case alternative, to find any here documents, and handle "$#". 173 ;; case alternative, to find any here documents, and handle "$#".
174 ;; 2. Setting the text property makes the buffer modified. If the 174 ;; 2. Setting the text property makes the buffer modified. If the
175 ;; buffer is read-only buffer we have to cheat and bypass the read-only 175 ;; buffer is read-only buffer we have to cheat and bypass the read-only
176 ;; status. This is for cases where the buffer started read-only buffer 176 ;; status. This is for cases where the buffer started read-only buffer
177 ;; but the user issued `toggle-read-only'. 177 ;; but the user issued `toggle-read-only'.
178 ;; 178 ;;
179 ;; Bugs 179 ;; Bugs
180 ;; ---- 180 ;; ----
181 ;; - Indenting many lines is slow. It currently does each line 181 ;; - Indenting many lines is slow. It currently does each line
182 ;; independently, rather than saving state information. 182 ;; independently, rather than saving state information.
183 ;; 183 ;;
184 ;; - `sh-learn-buffer-indent' is extremely slow. 184 ;; - `sh-learn-buffer-indent' is extremely slow.
185 ;; 185 ;;
186 ;; Richard Sharman <rsharman@pobox.com> June 1999. 186 ;; Richard Sharman <rsharman@pobox.com> June 1999.
187 187
188 ;;; Code: 188 ;;; Code:
189 189
190 ;; page 1: variables and settings 190 ;; page 1: variables and settings
826 (make-variable-buffer-local 'sh-here-doc-re) 826 (make-variable-buffer-local 'sh-here-doc-re)
827 827
828 (defun sh-font-lock-close-heredoc (bol eof indented) 828 (defun sh-font-lock-close-heredoc (bol eof indented)
829 "Determine the syntax of the \\n after an EOF. 829 "Determine the syntax of the \\n after an EOF.
830 If non-nil INDENTED indicates that the EOF was indented." 830 If non-nil INDENTED indicates that the EOF was indented."
831 (let* (;; A rough regexp that should find the opening <<EOF back. 831 (let* ((eof-re (regexp-quote eof))
832 ;; A rough regexp that should find the opening <<EOF back.
832 (sre (concat "<<\\(-?\\)\\s-*['\"\\]?" 833 (sre (concat "<<\\(-?\\)\\s-*['\"\\]?"
833 ;; Use \s| to cheaply check it's an open-heredoc. 834 ;; Use \s| to cheaply check it's an open-heredoc.
834 (regexp-quote eof) "['\"]?\\([ \t|;&)<>].*\\)?\\s|")) 835 eof-re "['\"]?\\([ \t|;&)<>].*\\)?\\s|"))
835 ;; A regexp that will find other EOFs. 836 ;; A regexp that will find other EOFs.
836 (ere (concat "^" (if indented "[ \t]*") (regexp-quote eof) "\n")) 837 (ere (concat "^" (if indented "[ \t]*") eof-re "\n"))
837 (start (save-excursion 838 (start (save-excursion
838 (goto-char bol) 839 (goto-char bol)
839 (re-search-backward (concat sre "\\|" ere) nil t)))) 840 (re-search-backward (concat sre "\\|" ere) nil t))))
840 ;; If subgroup 1 matched, we found an open-heredoc, otherwise we first 841 ;; If subgroup 1 matched, we found an open-heredoc, otherwise we first
841 ;; found a close-heredoc which makes the current close-heredoc inoperant. 842 ;; found a close-heredoc which makes the current close-heredoc inoperant.
918 (sh-font-lock-here-doc 919 (sh-font-lock-here-doc
919 (2 (sh-font-lock-open-heredoc 920 (2 (sh-font-lock-open-heredoc
920 (match-beginning 0) (match-string 1)) nil t) 921 (match-beginning 0) (match-string 1)) nil t)
921 (5 (sh-font-lock-close-heredoc 922 (5 (sh-font-lock-close-heredoc
922 (match-beginning 0) (match-string 4) 923 (match-beginning 0) (match-string 4)
923 (/= (match-beginning 3) (match-end 3))) nil t)) 924 (/= (match-beginning 3) (match-end 3))) nil t))
924 ;; Distinguish the special close-paren in `case'. 925 ;; Distinguish the special close-paren in `case'.
925 (")" 0 (sh-font-lock-paren (match-beginning 0))))) 926 (")" 0 (sh-font-lock-paren (match-beginning 0)))))
926 927
927 (defun sh-font-lock-syntactic-face-function (state) 928 (defun sh-font-lock-syntactic-face-function (state)
928 (if (nth 3 state) 929 (if (nth 3 state)
1965 ;; sh-indent-comment is t (indent as normal) 1966 ;; sh-indent-comment is t (indent as normal)
1966 (setq align-point (sh-prev-line nil)) 1967 (setq align-point (sh-prev-line nil))
1967 (setq have-result nil) 1968 (setq have-result nil)
1968 )) 1969 ))
1969 ) ;; cond 1970 ) ;; cond
1970 1971
1971 (unless have-result 1972 (unless have-result
1972 ;; Continuation lines are handled specially 1973 ;; Continuation lines are handled specially
1973 (if (sh-this-is-a-continuation) 1974 (if (sh-this-is-a-continuation)
1974 (progn 1975 (progn
1975 ;; We assume the line being continued is already 1976 ;; We assume the line being continued is already
2058 (sh-debug "result is %s" result) 2059 (sh-debug "result is %s" result)
2059 ) 2060 )
2060 (sh-debug "No prev line!") 2061 (sh-debug "No prev line!")
2061 (sh-debug "result: %s align-point: %s" result align-point) 2062 (sh-debug "result: %s align-point: %s" result align-point)
2062 ) 2063 )
2063 2064
2064 (if align-point 2065 (if align-point
2065 ;; was: (setq result (append result (list (list t align-point)))) 2066 ;; was: (setq result (append result (list (list t align-point))))
2066 (setq result (append (list (list t align-point)) result)) 2067 (setq result (append (list (list t align-point)) result))
2067 ) 2068 )
2068 (sh-debug "result is now: %s" result) 2069 (sh-debug "result is now: %s" result)
2069 2070
2070 (or result 2071 (or result
2071 (if prev-line-end 2072 (if prev-line-end
2072 (setq result (list (list t prev-line-end))) 2073 (setq result (list (list t prev-line-end)))
2073 (setq result (list (list '= 'sh-first-lines-indent))) 2074 (setq result (list (list '= 'sh-first-lines-indent)))
2074 )) 2075 ))
2075 2076
2076 (if (eq result t) 2077 (if (eq result t)
2077 (setq result nil)) 2078 (setq result nil))
2078 (sh-debug "result is: %s" result) 2079 (sh-debug "result is: %s" result)
2079 result 2080 result
2080 ) ;; let 2081 ) ;; let
2246 ;; 2247 ;;
2247 ;; Added a kludge for ";;" 2248 ;; Added a kludge for ";;"
2248 ;; Possible return values: 2249 ;; Possible return values:
2249 ;; nil - nothing 2250 ;; nil - nothing
2250 ;; a string - possibly a keyword 2251 ;; a string - possibly a keyword
2251 ;; 2252 ;;
2252 (if (bolp) 2253 (if (bolp)
2253 nil 2254 nil
2254 (let ((going t) 2255 (let ((going t)
2255 c n 2256 c n
2256 min-point 2257 min-point
2620 (message "%s set to %s" var (symbol-value var)) 2621 (message "%s set to %s" var (symbol-value var))
2621 ) 2622 )
2622 ((numberp (setq sval (sh-var-value var))) 2623 ((numberp (setq sval (sh-var-value var)))
2623 (setq ival (sh-calculate-indent info)) 2624 (setq ival (sh-calculate-indent info))
2624 (setq diff (- curr-indent ival)) 2625 (setq diff (- curr-indent ival))
2625 2626
2626 (sh-debug "curr-indent: %d ival: %d diff: %d var:%s sval %s" 2627 (sh-debug "curr-indent: %d ival: %d diff: %d var:%s sval %s"
2627 curr-indent ival diff var sval) 2628 curr-indent ival diff var sval)
2628 (setq new-val (+ sval diff)) 2629 (setq new-val (+ sval diff))
2629 ;;; I commented out this because someone might want to replace 2630 ;;; I commented out this because someone might want to replace
2630 ;;; a value of `+' with the current value of sh-basic-offset 2631 ;;; a value of `+' with the current value of sh-basic-offset
2697 2698
2698 ;; Is this really worth having? 2699 ;; Is this really worth having?
2699 (defvar sh-learned-buffer-hook nil 2700 (defvar sh-learned-buffer-hook nil
2700 "*An abnormal hook, called with an alist of learned variables.") 2701 "*An abnormal hook, called with an alist of learned variables.")
2701 ;; Example of how to use sh-learned-buffer-hook 2702 ;; Example of how to use sh-learned-buffer-hook
2702 ;; 2703 ;;
2703 ;; (defun what-i-learned (list) 2704 ;; (defun what-i-learned (list)
2704 ;; (let ((p list)) 2705 ;; (let ((p list))
2705 ;; (save-excursion 2706 ;; (save-excursion
2706 ;; (set-buffer "*scratch*") 2707 ;; (set-buffer "*scratch*")
2707 ;; (goto-char (point-max)) 2708 ;; (goto-char (point-max))
2710 ;; (insert (format " %s %s \n" 2711 ;; (insert (format " %s %s \n"
2711 ;; (nth 0 (car p)) (nth 1 (car p)))) 2712 ;; (nth 0 (car p)) (nth 1 (car p))))
2712 ;; (setq p (cdr p))) 2713 ;; (setq p (cdr p)))
2713 ;; (insert ")\n") 2714 ;; (insert ")\n")
2714 ;; ))) 2715 ;; )))
2715 ;; 2716 ;;
2716 ;; (add-hook 'sh-learned-buffer-hook 'what-i-learned) 2717 ;; (add-hook 'sh-learned-buffer-hook 'what-i-learned)
2717 2718
2718 2719
2719 ;; Originally this was sh-learn-region-indent (beg end) 2720 ;; Originally this was sh-learn-region-indent (beg end)
2720 ;; However, in practice this was awkward so I changed it to 2721 ;; However, in practice this was awkward so I changed it to
2902 (format "Possible value(s) for sh-basic-offset: %s" 2903 (format "Possible value(s) for sh-basic-offset: %s"
2903 (mapconcat 'int-to-string suggested " ")) 2904 (mapconcat 'int-to-string suggested " "))
2904 (format "Suggested sh-basic-offset: %d" suggested)) 2905 (format "Suggested sh-basic-offset: %d" suggested))
2905 nil out-buffer)))) 2906 nil out-buffer))))
2906 2907
2907 2908
2908 (setq learned-var-list 2909 (setq learned-var-list
2909 (append (list (list 'sh-indent-comment comment-col (point-max))) 2910 (append (list (list 'sh-indent-comment comment-col (point-max)))
2910 learned-var-list)) 2911 learned-var-list))
2911 (setq sh-indent-comment comment-col) 2912 (setq sh-indent-comment comment-col)
2912 (let ((name (buffer-name)) 2913 (let ((name (buffer-name))
3099 "case " str > \n 3100 "case " str > \n
3100 > _ \n) 3101 > _ \n)
3101 "case *" > \n 3102 "case *" > \n
3102 > _ \n 3103 > _ \n
3103 resume: 3104 resume:
3104 ?} > \n) 3105 ?\} > \n)
3105 (sh "expression: " 3106 (sh "expression: "
3106 > "case " str " in" \n 3107 > "case " str " in" \n
3107 > (read-string "pattern: ") 3108 > (read-string "pattern: ")
3108 (propertize ")" 'syntax-table sh-st-punc) 3109 (propertize ")" 'syntax-table sh-st-punc)
3109 \n 3110 \n
3130 (es eval sh-modify rc 3131 (es eval sh-modify rc
3131 4 " = ") 3132 4 " = ")
3132 (rc eval sh-modify sh 3133 (rc eval sh-modify sh
3133 2 "for( " 3134 2 "for( "
3134 6 " ) {" 3135 6 " ) {"
3135 15 ?} ) 3136 15 ?\} )
3136 (sh "Index variable: " 3137 (sh "Index variable: "
3137 > "for " str " in " _ "; do" \n 3138 > "for " str " in " _ "; do" \n
3138 > _ | ?$ & (sh-remember-variable str) \n 3139 > _ | ?$ & (sh-remember-variable str) \n
3139 "done" > \n)) 3140 "done" > \n))
3140 3141
3169 (rc "Index variable: " 3170 (rc "Index variable: "
3170 > "for( " str " in" " `{awk 'BEGIN { for( i=1; i<=" 3171 > "for( " str " in" " `{awk 'BEGIN { for( i=1; i<="
3171 (read-string "upper limit: ") 3172 (read-string "upper limit: ")
3172 "; i++ ) print i }'`}) {" \n 3173 "; i++ ) print i }'`}) {" \n
3173 > _ ?$ (sh-remember-variable str) \n 3174 > _ ?$ (sh-remember-variable str) \n
3174 ?} > \n) 3175 ?\} > \n)
3175 (sh "Index variable: " 3176 (sh "Index variable: "
3176 > "for " str " in `awk 'BEGIN { for( i=1; i<=" 3177 > "for " str " in `awk 'BEGIN { for( i=1; i<="
3177 (read-string "upper limit: ") 3178 (read-string "upper limit: ")
3178 "; i++ ) print i }'`; do" \n 3179 "; i++ ) print i }'`; do" \n
3179 > _ ?$ (sh-remember-variable str) \n 3180 > _ ?$ (sh-remember-variable str) \n
3283 "} { " str " } {" > \n 3284 "} { " str " } {" > \n
3284 > _ \n) 3285 > _ \n)
3285 "} {" > \n 3286 "} {" > \n
3286 > _ \n 3287 > _ \n
3287 resume: 3288 resume:
3288 ?} > \n) 3289 ?\} > \n)
3289 (rc "condition: " 3290 (rc "condition: "
3290 > "if( " str " ) {" \n 3291 > "if( " str " ) {" \n
3291 > _ \n 3292 > _ \n
3292 ( "other condition, %s: " 3293 ( "other condition, %s: "
3293 "} else if( " str " ) {" > \n 3294 "} else if( " str " ) {" > \n
3294 > _ \n) 3295 > _ \n)
3295 "} else {" > \n 3296 "} else {" > \n
3296 > _ \n 3297 > _ \n
3297 resume: 3298 resume:
3298 ?} > \n) 3299 ?\} > \n)
3299 (sh "condition: " 3300 (sh "condition: "
3300 '(setq input (sh-feature sh-test)) 3301 '(setq input (sh-feature sh-test))
3301 > "if " str "; then" \n 3302 > "if " str "; then" \n
3302 > _ \n 3303 > _ \n
3303 ( "other condition, %s: " 3304 ( "other condition, %s: "
3313 (define-skeleton sh-repeat 3314 (define-skeleton sh-repeat
3314 "Insert a repeat loop definition. See `sh-feature'." 3315 "Insert a repeat loop definition. See `sh-feature'."
3315 (es nil 3316 (es nil
3316 > "forever {" \n 3317 > "forever {" \n
3317 > _ \n 3318 > _ \n
3318 ?} > \n) 3319 ?\} > \n)
3319 (zsh "factor: " 3320 (zsh "factor: "
3320 > "repeat " str "; do" > \n 3321 > "repeat " str "; do" > \n
3321 > \n 3322 > \n
3322 "done" > \n)) 3323 "done" > \n))
3323 3324
3353 > "catch @ e {" \n 3354 > "catch @ e {" \n
3354 > "rm $tmp^* >[2]/dev/null" \n 3355 > "rm $tmp^* >[2]/dev/null" \n
3355 "throw $e" \n 3356 "throw $e" \n
3356 "} {" > \n 3357 "} {" > \n
3357 _ \n 3358 _ \n
3358 ?} > \n 3359 ?\} > \n
3359 ?} > \n) 3360 ?\} > \n)
3360 (ksh88 eval sh-modify sh 3361 (ksh88 eval sh-modify sh
3361 7 "EXIT") 3362 7 "EXIT")
3362 (rc (file-name-nondirectory (buffer-file-name)) 3363 (rc (file-name-nondirectory (buffer-file-name))
3363 > "tmp = /tmp/" str ".$pid" \n 3364 > "tmp = /tmp/" str ".$pid" \n
3364 "fn sigexit { rm $tmp^* >[2]/dev/null }" \n) 3365 "fn sigexit { rm $tmp^* >[2]/dev/null }" \n)
3388 10 '< 3389 10 '<
3389 11 "end") 3390 11 "end")
3390 (es eval sh-modify sh 3391 (es eval sh-modify sh
3391 3 "while { " 3392 3 "while { "
3392 5 " } {" 3393 5 " } {"
3393 10 ?} ) 3394 10 ?\} )
3394 (rc eval sh-modify sh 3395 (rc eval sh-modify sh
3395 3 "while( " 3396 3 "while( "
3396 5 " ) {" 3397 5 " ) {"
3397 10 ?} ) 3398 10 ?\} )
3398 (sh "condition: " 3399 (sh "condition: "
3399 '(setq input (sh-feature sh-test)) 3400 '(setq input (sh-feature sh-test))
3400 > "while " str "; do" \n 3401 > "while " str "; do" \n
3401 > _ \n 3402 > _ \n
3402 "done" > \n)) 3403 "done" > \n))