diff options
| author | Glenn Morris | 2005-04-13 18:49:57 +0000 |
|---|---|---|
| committer | Glenn Morris | 2005-04-13 18:49:57 +0000 |
| commit | 546e2f6ff26d1dcc0d590dfdbec9ceb0422cd7d1 (patch) | |
| tree | bb8f5167c7fe60bb42291cfc92f8c0959de2a268 | |
| parent | 328fc313667f4fca2185c6c5f03eca875be4d849 (diff) | |
| download | emacs-546e2f6ff26d1dcc0d590dfdbec9ceb0422cd7d1.tar.gz emacs-546e2f6ff26d1dcc0d590dfdbec9ceb0422cd7d1.zip | |
(sh-here-document-word): Make it a defcustom. Doc fix.
(sh-add): Bash uses $(( )) for arithmetic.
(sh-while-getopts) <sh>: Set OPTIND back to 1 at end.
(sh-maybe-here-document): Remove quotes and leading whitespace
from heredoc word when closing. Indent heredoc with tabs if word
starts with "-".
| -rw-r--r-- | lisp/progmodes/sh-script.el | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index 7015c0d943d..1a87dcaad0f 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el | |||
| @@ -555,14 +555,24 @@ The actual command ends at the end of the first \\(grouping\\)." | |||
| 555 | 555 | ||
| 556 | 556 | ||
| 557 | 557 | ||
| 558 | (defvar sh-here-document-word "EOF" | 558 | (defcustom sh-here-document-word "EOF" |
| 559 | "Word to delimit here documents. | 559 | "Word to delimit here documents. |
| 560 | If the first character of this string is \"-\", this character will | 560 | If the first character of this string is \"-\", this is taken as |
| 561 | be removed from the string when it is used to close the here document. | 561 | part of the redirection operator, rather than part of the |
| 562 | This convention is used by the Bash shell, for example, to indicate | 562 | word (that is, \"<<-\" instead of \"<<\"). This is a feature |
| 563 | that leading tabs inside the here document should be ignored. | 563 | used by some shells (for example Bash) to indicate that leading |
| 564 | Note that Emacs currently has no support for indenting inside here | 564 | tabs inside the here document should be ignored. In this case, |
| 565 | documents - you must insert literal tabs by hand.") | 565 | Emacs indents the initial body and end of the here document with |
| 566 | tabs, to the same level as the start (note that apart from this | ||
| 567 | there is no support for indentation of here documents). This | ||
| 568 | will only work correctly if `sh-basic-offset' is a multiple of | ||
| 569 | `tab-width'. | ||
| 570 | |||
| 571 | Any quote characters or leading whitespace in the word are | ||
| 572 | removed when closing the here document." | ||
| 573 | :type 'string | ||
| 574 | :group 'sh-script) | ||
| 575 | |||
| 566 | 576 | ||
| 567 | (defvar sh-test | 577 | (defvar sh-test |
| 568 | '((sh "[ ]" . 3) | 578 | '((sh "[ ]" . 3) |
| @@ -3247,7 +3257,7 @@ t means to return a list of all possible completions of STRING. | |||
| 3247 | (let ((sh-add-buffer (current-buffer))) | 3257 | (let ((sh-add-buffer (current-buffer))) |
| 3248 | (list (completing-read "Variable: " 'sh-add-completer) | 3258 | (list (completing-read "Variable: " 'sh-add-completer) |
| 3249 | (prefix-numeric-value current-prefix-arg)))) | 3259 | (prefix-numeric-value current-prefix-arg)))) |
| 3250 | (insert (sh-feature '((bash . "$[ ") | 3260 | (insert (sh-feature '((bash . "$(( ") |
| 3251 | (ksh88 . "$(( ") | 3261 | (ksh88 . "$(( ") |
| 3252 | (posix . "$(( ") | 3262 | (posix . "$(( ") |
| 3253 | (rc . "`{expr $") | 3263 | (rc . "`{expr $") |
| @@ -3256,7 +3266,7 @@ t means to return a list of all possible completions of STRING. | |||
| 3256 | (sh-remember-variable var) | 3266 | (sh-remember-variable var) |
| 3257 | (if (< delta 0) " - " " + ") | 3267 | (if (< delta 0) " - " " + ") |
| 3258 | (number-to-string (abs delta)) | 3268 | (number-to-string (abs delta)) |
| 3259 | (sh-feature '((bash . " ]") | 3269 | (sh-feature '((bash . " ))") |
| 3260 | (ksh88 . " ))") | 3270 | (ksh88 . " ))") |
| 3261 | (posix . " ))") | 3271 | (posix . " ))") |
| 3262 | (rc . "}") | 3272 | (rc . "}") |
| @@ -3482,7 +3492,8 @@ option followed by a colon `:' if the option accepts an argument." | |||
| 3482 | "esac" > | 3492 | "esac" > |
| 3483 | \n "done" | 3493 | \n "done" |
| 3484 | > \n | 3494 | > \n |
| 3485 | "shift " (sh-add "OPTIND" -1) \n)) | 3495 | "shift " (sh-add "OPTIND" -1) \n |
| 3496 | "OPTIND=1" \n)) | ||
| 3486 | 3497 | ||
| 3487 | 3498 | ||
| 3488 | 3499 | ||
| @@ -3500,7 +3511,6 @@ option followed by a colon `:' if the option accepts an argument." | |||
| 3500 | (match-string 1)))))) | 3511 | (match-string 1)))))) |
| 3501 | 3512 | ||
| 3502 | 3513 | ||
| 3503 | |||
| 3504 | (defun sh-maybe-here-document (arg) | 3514 | (defun sh-maybe-here-document (arg) |
| 3505 | "Insert self. Without prefix, following unquoted `<' inserts here document. | 3515 | "Insert self. Without prefix, following unquoted `<' inserts here document. |
| 3506 | The document is bounded by `sh-here-document-word'." | 3516 | The document is bounded by `sh-here-document-word'." |
| @@ -3511,18 +3521,21 @@ The document is bounded by `sh-here-document-word'." | |||
| 3511 | (save-excursion | 3521 | (save-excursion |
| 3512 | (backward-char 2) | 3522 | (backward-char 2) |
| 3513 | (sh-quoted-p)) | 3523 | (sh-quoted-p)) |
| 3514 | (progn | 3524 | (let ((tabs (if (string-match "\\`-" sh-here-document-word) |
| 3525 | (make-string (/ (current-indentation) tab-width) ?\t) | ||
| 3526 | "")) | ||
| 3527 | (delim (replace-regexp-in-string "['\"]" "" | ||
| 3528 | sh-here-document-word))) | ||
| 3515 | (insert sh-here-document-word) | 3529 | (insert sh-here-document-word) |
| 3516 | (or (eolp) (looking-at "[ \t]") (insert ? )) | 3530 | (or (eolp) (looking-at "[ \t]") (insert ? )) |
| 3517 | (end-of-line 1) | 3531 | (end-of-line 1) |
| 3518 | (while | 3532 | (while |
| 3519 | (sh-quoted-p) | 3533 | (sh-quoted-p) |
| 3520 | (end-of-line 2)) | 3534 | (end-of-line 2)) |
| 3521 | (newline) | 3535 | (insert ?\n tabs) |
| 3522 | (save-excursion | 3536 | (save-excursion |
| 3523 | (insert ?\n (substring | 3537 | (insert ?\n tabs (replace-regexp-in-string |
| 3524 | sh-here-document-word | 3538 | "\\`-?[ \t]*" "" delim)))))) |
| 3525 | (if (string-match "^-" sh-here-document-word) 1 0))))))) | ||
| 3526 | 3539 | ||
| 3527 | 3540 | ||
| 3528 | ;; various other commands | 3541 | ;; various other commands |
| @@ -3574,7 +3587,7 @@ With an argument, deletes the backslashes. | |||
| 3574 | 3587 | ||
| 3575 | This function does not modify the last line of the region if the region ends | 3588 | This function does not modify the last line of the region if the region ends |
| 3576 | right at the start of the following line; it does not modify blank lines | 3589 | right at the start of the following line; it does not modify blank lines |
| 3577 | at the start of the region. So you can put the region around an entire | 3590 | at the start of the region. So you can put the region around an entire |
| 3578 | shell command and conveniently use this command." | 3591 | shell command and conveniently use this command." |
| 3579 | (interactive "r\nP") | 3592 | (interactive "r\nP") |
| 3580 | (save-excursion | 3593 | (save-excursion |