]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/sh-script.el
(sh-font-lock-keywords-1): Revert inadvertently installed patch hunk.
[gnu-emacs] / lisp / progmodes / sh-script.el
index ef80d28c578c785cf9415947fc9a09aa70d02c73..d69229780b6bf87d0f6a275dbb9cefdc0eb6511c 100644 (file)
@@ -982,7 +982,10 @@ Point is at the beginning of the next line."
 (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."
-  (if (re-search-forward "\"\\(?:.\\|\n\\)*?\\(\\$(\\|`\\)" limit t)
+  ;; 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)
@@ -1002,23 +1005,27 @@ Point is at the beginning of the next line."
           ;; ( [preceeded by $ ]   => increase nesting
           ;; " [nesting <= 0 ]     => terminate, we're done.
           ;; " [nesting >  0 ]     => remember this, it's not a proper "
-          (if (eq ?\\ last) nil
-            (if (eq ?\` char) (setq nest (+ nest (if bq -1 1)) bq (not bq))
-              (if (and (> nest 0) (eq ?\) char))  (setq nest (1- nest))
-                (if (and (eq ?$ last) (eq ?\( char)) (setq nest (1+ nest))
-                  (if (and (> nest 0) (eq ?\( char)) (setq nest (1+ nest))
-                    (if (eq char ?\")
-                        (if (>= 0 nest) (setq continue nil)
-                          (setq seen (cons pos seen)) ) ))))))
+          ;; 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)))
-          (mapc (lambda (P)
-                  (setq data (cons P (cons (1+ P) data)) ) ) seen)
+          (dolist(P seen)
+            (setq data (cons P (cons (1+ P) data))))
           (store-match-data data))
         data) ))