diff options
| author | Karl Heuer | 1995-08-15 19:50:12 +0000 |
|---|---|---|
| committer | Karl Heuer | 1995-08-15 19:50:12 +0000 |
| commit | 225f6185dfef040e49b1f1dabd3b57a3e414e149 (patch) | |
| tree | a1697a832d8763002409fa9586d73dbe96c2534c | |
| parent | 773500abf69ff95c1ad01cc74dd93d92a654e638 (diff) | |
| download | emacs-225f6185dfef040e49b1f1dabd3b57a3e414e149.tar.gz emacs-225f6185dfef040e49b1f1dabd3b57a3e414e149.zip | |
(sh-test): New variable.
(sh-if, sh-until, sh-while): Use it.
(sh-while-getopts): Handle csh passably well.
(sh-font-lock-keywords): Use `font-lock-variable-name-face'.
(sh-set-shell): Respect `font-lock-maximum-decoration'.
| -rw-r--r-- | lisp/progmodes/sh-script.el | 91 |
1 files changed, 59 insertions, 32 deletions
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index 1d6318e7cb7..9c03c5f63f2 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el | |||
| @@ -169,7 +169,8 @@ shell it really is.") | |||
| 169 | 169 | ||
| 170 | (defvar sh-abbrevs | 170 | (defvar sh-abbrevs |
| 171 | '((csh eval sh-abbrevs shell | 171 | '((csh eval sh-abbrevs shell |
| 172 | "switch" 'sh-case) | 172 | "switch" 'sh-case |
| 173 | "getopts" 'sh-while-getopts) | ||
| 173 | 174 | ||
| 174 | (es eval sh-abbrevs shell | 175 | (es eval sh-abbrevs shell |
| 175 | "function" 'sh-function) | 176 | "function" 'sh-function) |
| @@ -361,6 +362,11 @@ The actual command ends at the end of the first \\(grouping\\).") | |||
| 361 | (defvar sh-here-document-word "EOF" | 362 | (defvar sh-here-document-word "EOF" |
| 362 | "Word to delimit here documents.") | 363 | "Word to delimit here documents.") |
| 363 | 364 | ||
| 365 | (defvar sh-test | ||
| 366 | '((sh "[ ]" . 3) | ||
| 367 | (ksh88 "[[ ]]" . 4)) | ||
| 368 | "Initial input in Bourne if, while and until skeletons. See `sh-feature'.") | ||
| 369 | |||
| 364 | 370 | ||
| 365 | (defvar sh-builtins | 371 | (defvar sh-builtins |
| 366 | '((bash eval sh-append sh | 372 | '((bash eval sh-append sh |
| @@ -376,7 +382,7 @@ The actual command ends at the end of the first \\(grouping\\).") | |||
| 376 | "until") | 382 | "until") |
| 377 | 383 | ||
| 378 | (csh eval sh-append shell | 384 | (csh eval sh-append shell |
| 379 | "alias" "breaksw" "chdir" "default" "end" "endif" "endsw" "foreach" | 385 | "alias" "breaksw" "chdir" "default:" "end" "endif" "endsw" "foreach" |
| 380 | "glob" "goto" "history" "limit" "logout" "nice" "nohup" "onintr" | 386 | "glob" "goto" "history" "limit" "logout" "nice" "nohup" "onintr" |
| 381 | "rehash" "repeat" "setenv" "source" "switch" "time" "unalias" | 387 | "rehash" "repeat" "setenv" "source" "switch" "time" "unalias" |
| 382 | "unhash") | 388 | "unhash") |
| @@ -532,15 +538,13 @@ See `sh-feature'.") | |||
| 532 | (defvar sh-font-lock-keywords | 538 | (defvar sh-font-lock-keywords |
| 533 | '((csh eval sh-append shell | 539 | '((csh eval sh-append shell |
| 534 | '("\\${?[#?]?\\([A-Za-z_][A-Za-z0-9_]*\\|0\\)" 1 | 540 | '("\\${?[#?]?\\([A-Za-z_][A-Za-z0-9_]*\\|0\\)" 1 |
| 535 | font-lock-function-name-face) | 541 | font-lock-variable-name-face)) |
| 536 | '("\\(^\\|[ \t]\\)\\(default\\):" 2 | ||
| 537 | font-lock-keyword-face t)) | ||
| 538 | 542 | ||
| 539 | (dtksh eval identity wksh) | 543 | (dtksh eval identity wksh) |
| 540 | 544 | ||
| 541 | (es eval sh-append executable-font-lock-keywords | 545 | (es eval sh-append executable-font-lock-keywords |
| 542 | '("\\$#?\\([A-Za-z_][A-Za-z0-9_]*\\|[0-9]+\\)" 1 | 546 | '("\\$#?\\([A-Za-z_][A-Za-z0-9_]*\\|[0-9]+\\)" 1 |
| 543 | font-lock-function-name-face)) | 547 | font-lock-variable-name-face)) |
| 544 | 548 | ||
| 545 | (rc eval sh-append es | 549 | (rc eval sh-append es |
| 546 | '("\\(^\\|[ \t]\\)\\(else\\( if\\)?\\)\\>" 2 | 550 | '("\\(^\\|[ \t]\\)\\(else\\( if\\)?\\)\\>" 2 |
| @@ -548,14 +552,14 @@ See `sh-feature'.") | |||
| 548 | 552 | ||
| 549 | (sh eval sh-append shell | 553 | (sh eval sh-append shell |
| 550 | '("\\$\\({#?\\)?\\([A-Za-z_][A-Za-z0-9_]*\\|[-#?@!]\\)" 2 | 554 | '("\\$\\({#?\\)?\\([A-Za-z_][A-Za-z0-9_]*\\|[-#?@!]\\)" 2 |
| 551 | font-lock-function-name-face) | 555 | font-lock-variable-name-face) |
| 552 | " in\\([ \t]\\|$\\)") | 556 | " in\\([ \t]\\|$\\)") |
| 553 | 557 | ||
| 554 | ;; The next entry is only used for defining the others | 558 | ;; The next entry is only used for defining the others |
| 555 | (shell eval sh-append executable-font-lock-keywords | 559 | (shell eval sh-append executable-font-lock-keywords |
| 556 | '("\\\\." 0 font-lock-string-face) | 560 | '("\\\\." 0 font-lock-string-face) |
| 557 | '("\\${?\\([A-Za-z_][A-Za-z0-9_]*\\|[0-9]+\\|[$*_]\\)" 1 | 561 | '("\\${?\\([A-Za-z_][A-Za-z0-9_]*\\|[0-9]+\\|[$*_]\\)" 1 |
| 558 | font-lock-function-name-face)) | 562 | font-lock-variable-name-face)) |
| 559 | 563 | ||
| 560 | (wksh eval sh-append ksh88 | 564 | (wksh eval sh-append ksh88 |
| 561 | '("\\(^\\|[^-._A-Za-z0-9]\\)\\(Xt[A-Z][A-Za-z]*\\)\\($\\|[^-._A-Za-z0-9]\\)" 2 font-lock-keyword-face))) | 565 | '("\\(^\\|[^-._A-Za-z0-9]\\)\\(Xt[A-Z][A-Za-z]*\\)\\($\\|[^-._A-Za-z0-9]\\)" 2 font-lock-keyword-face))) |
| @@ -679,26 +683,23 @@ Calls the value of `sh-set-shell-hook' if set." | |||
| 679 | (sh-feature | 683 | (sh-feature |
| 680 | sh-font-lock-keywords | 684 | sh-font-lock-keywords |
| 681 | (lambda (list) | 685 | (lambda (list) |
| 682 | (sh-append list | 686 | `((,(concat (sh-feature sh-comment-prefix) "\\(#.*\\)") |
| 683 | (cons (concat (sh-feature sh-comment-prefix) | 687 | 2 font-lock-comment-face t) |
| 684 | "\\(#.*\\)") | 688 | (,(sh-feature sh-assignment-regexp) |
| 685 | '(2 font-lock-comment-face t)) | 689 | 1 font-lock-variable-name-face) |
| 686 | ;; first grouping should include all keywords such | 690 | ,@(if font-lock-maximum-decoration |
| 687 | ;; as while, do ... that may be followed by a | 691 | `((,(concat "\\(^\\|[|&;()]\\)[ \t]*\\(\\(\\(" |
| 688 | ;; command, but neither t nor keep will fontify it | 692 | (mapconcat 'identity |
| 689 | (cons (concat "\\(^\\|[|&;()]\\)[ \t]*\\(\\(\\(" | 693 | (sh-feature sh-leading-keywords) |
| 690 | (mapconcat 'identity | 694 | "\\|") |
| 691 | (sh-feature | 695 | "\\)[ \t]+\\)?\\(" |
| 692 | sh-leading-keywords) | 696 | (mapconcat 'identity |
| 693 | "\\|") | 697 | (sh-feature sh-builtins) |
| 694 | "\\)[ \t]+\\)?\\(" | 698 | "\\|") |
| 695 | (mapconcat 'identity | 699 | "\\)\\)\\($\\|[ \t|&;()]\\)") |
| 696 | (sh-feature sh-builtins) | 700 | 2 font-lock-keyword-face 'keep) |
| 697 | "\\|") | 701 | ,@list) |
| 698 | "\\)\\)\\($\\|[ \t|&;()]\\)") | 702 | list)))) |
| 699 | '(2 font-lock-keyword-face 'keep)) | ||
| 700 | (cons (sh-feature sh-assignment-regexp) | ||
| 701 | '(1 font-lock-function-name-face))))) | ||
| 702 | comment-start-skip (concat (sh-feature sh-comment-prefix) "#+[\t ]*") | 703 | comment-start-skip (concat (sh-feature sh-comment-prefix) "#+[\t ]*") |
| 703 | mode-line-process (format "[%s]" sh-shell) | 704 | mode-line-process (format "[%s]" sh-shell) |
| 704 | process-environment (default-value 'process-environment) | 705 | process-environment (default-value 'process-environment) |
| @@ -1074,10 +1075,11 @@ region, clear header." | |||
| 1074 | 10 "} else {" | 1075 | 10 "} else {" |
| 1075 | 17 ?}) | 1076 | 17 ?}) |
| 1076 | (sh "condition: " | 1077 | (sh "condition: " |
| 1077 | "if [ " str " ]; then" \n | 1078 | '(setq input (sh-feature sh-test)) |
| 1079 | "if " str "; then" \n | ||
| 1078 | > _ \n | 1080 | > _ \n |
| 1079 | ( "other condition, %s: " | 1081 | ( "other condition, %s: " |
| 1080 | < "elif [ " str " ]; then" \n | 1082 | < "elif " str "; then" \n |
| 1081 | > _ \n) | 1083 | > _ \n) |
| 1082 | < "else" \n | 1084 | < "else" \n |
| 1083 | > _ \n | 1085 | > _ \n |
| @@ -1144,7 +1146,8 @@ region, clear header." | |||
| 1144 | (define-skeleton sh-until | 1146 | (define-skeleton sh-until |
| 1145 | "Insert an until loop. See `sh-feature'." | 1147 | "Insert an until loop. See `sh-feature'." |
| 1146 | (sh "condition: " | 1148 | (sh "condition: " |
| 1147 | "until [ " str " ]; do" \n | 1149 | '(setq input (sh-feature sh-test)) |
| 1150 | "until " str "; do" \n | ||
| 1148 | > _ \n | 1151 | > _ \n |
| 1149 | < "done")) | 1152 | < "done")) |
| 1150 | (put 'sh-until 'menu-enable '(sh-feature sh-until)) | 1153 | (put 'sh-until 'menu-enable '(sh-feature sh-until)) |
| @@ -1164,7 +1167,8 @@ region, clear header." | |||
| 1164 | 3 " ) {" | 1167 | 3 " ) {" |
| 1165 | 9 ?}) | 1168 | 9 ?}) |
| 1166 | (sh "condition: " | 1169 | (sh "condition: " |
| 1167 | "while [ " str " ]; do" \n | 1170 | '(setq input (sh-feature sh-test)) |
| 1171 | "while " str "; do" \n | ||
| 1168 | > _ \n | 1172 | > _ \n |
| 1169 | < "done")) | 1173 | < "done")) |
| 1170 | 1174 | ||
| @@ -1176,6 +1180,29 @@ Prompts for an options string which consists of letters for each recognized | |||
| 1176 | option followed by a colon `:' if the option accepts an argument." | 1180 | option followed by a colon `:' if the option accepts an argument." |
| 1177 | (bash eval sh-modify sh | 1181 | (bash eval sh-modify sh |
| 1178 | 18 "${0##*/}") | 1182 | 18 "${0##*/}") |
| 1183 | (csh nil | ||
| 1184 | "while( 1 )" \n | ||
| 1185 | > "switch( \"$1\" )" \n | ||
| 1186 | '(setq input '("- x" . 2)) | ||
| 1187 | > > | ||
| 1188 | ( "option, %s: " | ||
| 1189 | < "case " '(eval str) | ||
| 1190 | '(if (string-match " +" str) | ||
| 1191 | (setq v1 (substring str (match-end 0)) | ||
| 1192 | str (substring str 0 (match-beginning 0))) | ||
| 1193 | (setq v1 nil)) | ||
| 1194 | str ?: \n | ||
| 1195 | > "set " v1 & " = $2" | -4 & _ \n | ||
| 1196 | (if v1 "shift") & \n | ||
| 1197 | "breaksw" \n) | ||
| 1198 | < "case --:" \n | ||
| 1199 | > "shift" \n | ||
| 1200 | < "default:" \n | ||
| 1201 | > "break" \n | ||
| 1202 | resume: | ||
| 1203 | < < "endsw" \n | ||
| 1204 | "shift" \n | ||
| 1205 | < "end") | ||
| 1179 | (ksh88 eval sh-modify sh | 1206 | (ksh88 eval sh-modify sh |
| 1180 | 16 "print" | 1207 | 16 "print" |
| 1181 | 18 "${0##*/}" | 1208 | 18 "${0##*/}" |