changeset 72044:3dc0557bba5f

(sh-quoted-subshell): Further fix last change.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 20 Jul 2006 21:23:48 +0000
parents dce50dd248c3
children 52eb98c2d37f
files lisp/ChangeLog lisp/progmodes/sh-script.el
diffstat 2 files changed, 54 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Thu Jul 20 20:34:36 2006 +0000
+++ b/lisp/ChangeLog	Thu Jul 20 21:23:48 2006 +0000
@@ -1,3 +1,7 @@
+2006-07-20  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* progmodes/sh-script.el (sh-quoted-subshell): Further fix last change.
+
 2006-07-20  Jay Belanger  <belanger@truman.edu>
 
 	* calc.el (calc-previous-alg-entry):  Remove variable.
@@ -12,7 +16,7 @@
 	(calcAlg-previous): Use `previous-history-element' instead of
 	`calc-previous-alg-entry'.
 	(calc-do-alg-entry): Use history when calling `read-from-minibuffer'.
-	Change keybinding for `calcAlg-plus-minus', add keybindings for	
+	Change keybinding for `calcAlg-plus-minus', add keybindings for
 	`previous-history-element' and `next-history-element'.
 
 	* calc-rewr.el (calc-match): Remove reference to
@@ -35,14 +39,14 @@
 
 2006-07-20  Alan Mackenzie  <acm@muc.de>
 
-	* progmodes/cc-langs.el (c-emacs-variable-inits): new variable.
-	(c-lang-setvar): new macro.
+	* progmodes/cc-langs.el (c-emacs-variable-inits): New variable.
+	(c-lang-setvar): New macro.
 	(c-make-init-lang-vars-fun): Use the initialization forms in
 	c-emacs-variable-inits in addition to those in c-lang-variable-inits.
 	(comment-start, comment-end, comment-start-skip): Change these from
 	c-lang-defvar's to c-lang-setvar's.
 
-	* progmodes/cc-mode.el (c-make-emacs-variables-local): new macro,
+	* progmodes/cc-mode.el (c-make-emacs-variables-local): New macro,
 	which calls make-local-variable on the elements of
 	c-emacs-variable-inits.
 	(c-init-language-vars-for): Call this new macro.
--- a/lisp/progmodes/sh-script.el	Thu Jul 20 20:34:36 2006 +0000
+++ b/lisp/progmodes/sh-script.el	Thu Jul 20 21:23:48 2006 +0000
@@ -980,54 +980,55 @@
   (re-search-forward sh-here-doc-re limit t))
 
 (defun sh-quoted-subshell (limit)
-  "Search for a subshell embedded in a string. Find all the unescaped
-\" characters within said subshell, remembering that subshells can nest."
+  "Search for a subshell embedded in a string.
+Find all the unescaped \" characters within said subshell, remembering that
+subshells can nest."
   ;; FIXME: This can (and often does) match multiple lines, yet it makes no
   ;; effort to handle multiline cases correctly, so it ends up being
   ;; rather flakey.
-  (if (re-search-forward "\"\\(?:\\(?:.\\|\n\\)*?[^\\]\\(\\\\\\\\\\)*\\)??\\(\\$(\\|`\\)" limit t)
-      ;; bingo we have a $( or a ` inside a ""
-      (let ((char (char-after (point)))
-            (continue t)
-            (pos (point))
-            (data nil)    ;; value to put into match-data (and return)
-            (last nil)    ;; last char seen
-            (bq  (equal (match-string 1) "`")) ;; ` state flip-flop
-            (seen nil)    ;; list of important positions
-            (nest 1))     ;; subshell nesting level
-        (while (and continue char (<= pos limit))
-          ;; unescaped " inside a $( ... ) construct.
-          ;; state machine time...
-          ;; \ => ignore next char;
-          ;; ` => increase or decrease nesting level based on bq flag
-          ;; ) [where nesting > 0] => decrease nesting
-          ;; ( [where nesting > 0] => increase nesting
-          ;; ( [preceeded by $ ]   => increase nesting
-          ;; " [nesting <= 0 ]     => terminate, we're done.
-          ;; " [nesting >  0 ]     => remember this, it's not a proper "
-          ;; FIXME: don't count parens that appear within quotes.
-          (cond
-           ((eq ?\\ last) nil)
-           ((eq ?\` char) (setq nest (+ nest (if bq -1 1)) bq (not bq)))
-           ((and (> nest 0) (eq ?\) char))   (setq nest (1- nest)))
-           ((and (eq ?$ last) (eq ?\( char)) (setq nest (1+ nest)))
-           ((and (> nest 0) (eq ?\( char))   (setq nest (1+ nest)))
-           ((eq char ?\")
-            (if (>= 0 nest) (setq continue nil) (push pos seen))))
-          ;;(message "POS: %d [%d]" pos nest)
-          (setq last char
-                pos  (1+ pos)
-                char (char-after pos)) )
-        ;; FIXME: why construct a costly match data to pass to
-        ;; sh-apply-quoted-subshell rather than apply the highlight
-        ;; directly here?  -- Stef
-        (when seen
-          ;;(message "SEEN: %S" seen)
-          (setq data (list (current-buffer)))
-          (dolist(P seen)
-            (setq data (cons P (cons (1+ P) data))))
-          (store-match-data data))
-        data) ))
+  (when (re-search-forward "\"\\(?:\\(?:.\\|\n\\)*?[^\\]\\(?:\\\\\\\\\\)*\\)??\\(\\$(\\|`\\)" limit t)
+    ;; bingo we have a $( or a ` inside a ""
+    (let ((char (char-after (point)))
+          (continue t)
+          (pos (point))
+          (data nil)      ;; value to put into match-data (and return)
+          (last nil)      ;; last char seen
+          (bq  (equal (match-string 1) "`")) ;; ` state flip-flop
+          (seen nil)                         ;; list of important positions
+          (nest 1))                          ;; subshell nesting level
+      (while (and continue char (<= pos limit))
+        ;; unescaped " inside a $( ... ) construct.
+        ;; state machine time...
+        ;; \ => ignore next char;
+        ;; ` => increase or decrease nesting level based on bq flag
+        ;; ) [where nesting > 0] => decrease nesting
+        ;; ( [where nesting > 0] => increase nesting
+        ;; ( [preceeded by $ ]   => increase nesting
+        ;; " [nesting <= 0 ]     => terminate, we're done.
+        ;; " [nesting >  0 ]     => remember this, it's not a proper "
+        ;; FIXME: don't count parens that appear within quotes.
+        (cond
+         ((eq ?\\ last) nil)
+         ((eq ?\` char) (setq nest (+ nest (if bq -1 1)) bq (not bq)))
+         ((and (> nest 0) (eq ?\) char))   (setq nest (1- nest)))
+         ((and (eq ?$ last) (eq ?\( char)) (setq nest (1+ nest)))
+         ((and (> nest 0) (eq ?\( char))   (setq nest (1+ nest)))
+         ((eq char ?\")
+          (if (>= 0 nest) (setq continue nil) (push pos seen))))
+        ;;(message "POS: %d [%d]" pos nest)
+        (setq last char
+              pos  (1+ pos)
+              char (char-after pos)) )
+      ;; FIXME: why construct a costly match data to pass to
+      ;; sh-apply-quoted-subshell rather than apply the highlight
+      ;; directly here?  -- Stef
+      (when seen
+        ;;(message "SEEN: %S" seen)
+        (setq data (list (current-buffer)))
+        (dolist(P seen)
+          (setq data (cons P (cons (1+ P) data))))
+        (store-match-data data))
+      data) ))
 
 (defun sh-is-quoted-p (pos)
   (and (eq (char-before pos) ?\\)