diff options
author | Karoly Lorentey <lorentey@elte.hu> | 2006-07-29 09:59:12 +0000 |
---|---|---|
committer | Karoly Lorentey <lorentey@elte.hu> | 2006-07-29 09:59:12 +0000 |
commit | 251bc578cc636223d618d06cf2a2bb7d07db9cce (patch) | |
tree | 58e1c6b0a35bb4a77e6cb77876e4bc6a9d3f2ab2 /lisp/progmodes/sh-script.el | |
parent | 99715bbc447eb633e45ffa23b87284771ce3ac74 (diff) | |
parent | 0ed0527cb02180a50f6744086ce3a487740c73e4 (diff) | |
download | emacs-251bc578cc636223d618d06cf2a2bb7d07db9cce.tar.gz emacs-251bc578cc636223d618d06cf2a2bb7d07db9cce.tar.bz2 emacs-251bc578cc636223d618d06cf2a2bb7d07db9cce.zip |
Merged from emacs@sv.gnu.org
Patches applied:
* emacs@sv.gnu.org/emacs--devo--0--patch-351
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-352
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-353
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-354
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-355
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-356
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-357
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-358
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-359
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-360
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-361
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-362
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-363
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-364
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-365
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-366
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-367
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-368
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-369
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-370
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-115
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-116
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-117
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-118
Merge from emacs--devo--0
* emacs@sv.gnu.org/gnus--rel--5.10--patch-119
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-120
Update from CVS
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-573
Diffstat (limited to 'lisp/progmodes/sh-script.el')
-rw-r--r-- | lisp/progmodes/sh-script.el | 90 |
1 files changed, 49 insertions, 41 deletions
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index ef80d28c578..6098c8be067 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el @@ -980,47 +980,55 @@ Point is at the beginning of the next line." (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." - (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 " - (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)) ) )))))) - ;;(message "POS: %d [%d]" pos nest) - (setq last char - pos (1+ pos) - char (char-after pos)) ) - (when seen - ;;(message "SEEN: %S" seen) - (setq data (list (current-buffer))) - (mapc (lambda (P) - (setq data (cons P (cons (1+ P) data)) ) ) seen) - (store-match-data data)) - data) )) + "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. + (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) ?\\) |