aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/progmodes/sh-script.el47
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.
560If the first character of this string is \"-\", this character will 560If the first character of this string is \"-\", this is taken as
561be removed from the string when it is used to close the here document. 561part of the redirection operator, rather than part of the
562This convention is used by the Bash shell, for example, to indicate 562word (that is, \"<<-\" instead of \"<<\"). This is a feature
563that leading tabs inside the here document should be ignored. 563used by some shells (for example Bash) to indicate that leading
564Note that Emacs currently has no support for indenting inside here 564tabs inside the here document should be ignored. In this case,
565documents - you must insert literal tabs by hand.") 565Emacs indents the initial body and end of the here document with
566tabs, to the same level as the start (note that apart from this
567there is no support for indentation of here documents). This
568will only work correctly if `sh-basic-offset' is a multiple of
569`tab-width'.
570
571Any quote characters or leading whitespace in the word are
572removed 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.
3506The document is bounded by `sh-here-document-word'." 3516The 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
3575This function does not modify the last line of the region if the region ends 3588This function does not modify the last line of the region if the region ends
3576right at the start of the following line; it does not modify blank lines 3589right at the start of the following line; it does not modify blank lines
3577at the start of the region. So you can put the region around an entire 3590at the start of the region. So you can put the region around an entire
3578shell command and conveniently use this command." 3591shell command and conveniently use this command."
3579 (interactive "r\nP") 3592 (interactive "r\nP")
3580 (save-excursion 3593 (save-excursion