changeset 73239:b6db8e4b9bbe

(sh-prev-thing): Massage to untangle the control flow a bit, simplify another bit, and add comments.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 03 Oct 2006 20:44:26 +0000
parents 3acc9a097705
children 54742554f07e
files lisp/ChangeLog lisp/progmodes/sh-script.el
diffstat 2 files changed, 48 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Tue Oct 03 20:42:53 2006 +0000
+++ b/lisp/ChangeLog	Tue Oct 03 20:44:26 2006 +0000
@@ -1,3 +1,8 @@
+2006-10-03  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* progmodes/sh-script.el (sh-prev-thing): Massage to untangle the
+	control flow a bit, simplify another bit, and add comments.
+
 2006-10-03  David Kastrup  <dak@gnu.org>
 
 	* help.el (describe-mode): For clicks on mode-line, use "@"
--- a/lisp/progmodes/sh-script.el	Tue Oct 03 20:42:53 2006 +0000
+++ b/lisp/progmodes/sh-script.el	Tue Oct 03 20:44:26 2006 +0000
@@ -2460,55 +2460,49 @@
   ;;
   (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 ?\;))
-	 (let (done kwd next
-	       (boundary (point)))
-	   (skip-chars-forward " \t\n\\\\")
-	   (while (and (not done) (not (eobp)))
-	     (if next (setq boundary next))
-	     ;; skip forward over white space newline and \ at eol
-	     (sh-debug "Now at %d   start=%d" (point) start)
-	     (if (>= (point) start)
-		 (progn
-		   (sh-debug "point: %d >= start: %d" (point) start)
-		   nil)
-	       (setq kwd (sh-get-word))
-	       (unless (eobp) (forward-char 1))
-	       (if (member kwd (sh-feature sh-leading-keywords))
-		   (setq next (point))
-		 (setq done t)))
-	     (skip-chars-forward " \t\n\\\\"))
-	   (goto-char boundary)
-	   kwd))
-	 (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))
+                      ;; The reason for this next line is unclear.
+                      ;; <md5i@cs.cmu.edu> says "the need for this was
+                      ;; expermientally determined".  --Stef
+                      (when (< (point) start) (forward-char 1))
+                      (if (member kwd (sh-feature sh-leading-keywords))
+                          (progn
+                            (setq next (point))
+                            t)
+                        nil))))
+              (goto-char boundary)
+              kwd)))))))
 
 
 (defun sh-this-is-a-continuation ()