summaryrefslogtreecommitdiff
path: root/lisp/progmodes/sh-script.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/sh-script.el')
-rw-r--r--lisp/progmodes/sh-script.el81
1 files changed, 40 insertions, 41 deletions
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index f828c36917b..83b4bdea759 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -2460,46 +2460,45 @@ we go to the end of the previous line and do not check for continuations."
;;
(if (bolp)
nil
- (let (c min-point
- (start (point)))
- (save-restriction
- (narrow-to-region
- (if (sh-this-is-a-continuation)
- (setq min-point (sh-prev-line nil))
- (save-excursion
- (beginning-of-line)
- (setq min-point (point))))
- (point))
- (skip-chars-backward " \t;")
- (unless (looking-at "\\s-*;;")
- (skip-chars-backward "^)}];\"'`({[")
- (setq c (char-before))))
- (sh-debug "stopping at %d c is %s start=%d min-point=%d"
- (point) c start min-point)
- (if (< (point) min-point)
- (error "point %d < min-point %d" (point) min-point))
- (cond
- ((looking-at "\\s-*;;")
- ;; (message "Found ;; !")
- ";;")
- ((or (eq c ?\n)
- (eq c nil)
- (eq c ?\;))
- (save-excursion
- ;; skip forward over white space newline and \ at eol
- (skip-chars-forward " \t\n\\\\")
- (sh-debug "Now at %d start=%d" (point) start)
- (if (>= (point) start)
- (progn
- (sh-debug "point: %d >= start: %d" (point) start)
- nil)
- (sh-get-word))
- ))
- (t
- ;; c -- return a string
- (char-to-string c)
- ))
- )))
+ (let ((start (point))
+ (min-point (if (sh-this-is-a-continuation)
+ (sh-prev-line nil)
+ (line-beginning-position))))
+ (skip-chars-backward " \t;" min-point)
+ (if (looking-at "\\s-*;;")
+ ;; (message "Found ;; !")
+ ";;"
+ (skip-chars-backward "^)}];\"'`({[" min-point)
+ (let ((c (if (> (point) min-point) (char-before))))
+ (sh-debug "stopping at %d c is %s start=%d min-point=%d"
+ (point) c start min-point)
+ (if (not (memq c '(?\n nil ?\;)))
+ ;; c -- return a string
+ (char-to-string c)
+ ;; Return the leading keyword of the "command" we supposedly
+ ;; skipped over. Maybe we skipped too far (e.g. past a `do' or
+ ;; `then' that precedes the actual command), so check whether
+ ;; we're looking at such a keyword and if so, move back forward.
+ (let ((boundary (point))
+ kwd next)
+ (while
+ (progn
+ ;; Skip forward over white space newline and \ at eol.
+ (skip-chars-forward " \t\n\\\\" start)
+ (if (>= (point) start)
+ (progn
+ (sh-debug "point: %d >= start: %d" (point) start)
+ nil)
+ (if next (setq boundary next))
+ (sh-debug "Now at %d start=%d" (point) start)
+ (setq kwd (sh-get-word))
+ (if (member kwd (sh-feature sh-leading-keywords))
+ (progn
+ (setq next (point))
+ t)
+ nil))))
+ (goto-char boundary)
+ kwd)))))))
(defun sh-this-is-a-continuation ()
@@ -2518,7 +2517,7 @@ If AND-MOVE is non-nil then move to end of word."
(goto-char where))
(prog1
(buffer-substring (point)
- (progn (skip-chars-forward "^ \t\n;&")(point)))
+ (progn (skip-chars-forward "^ \t\n;&|()")(point)))
(unless and-move
(goto-char start)))))