From: Stefan Monnier Date: Thu, 20 Oct 2005 19:43:44 +0000 (+0000) Subject: (sh-escaped-line-re): New var. X-Git-Tag: emacs-pretest-22.0.90~6455 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9d37a5c0f54bfadc33017697b2579aa0554d0b23;p=emacs.git (sh-escaped-line-re): New var. (sh-here-doc-open-re, sh-font-lock-close-heredoc): Use it. (sh-font-lock-open-heredoc): Try to properly handle heredoc starters whose line is either continued or ends with a comment. --- diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index b8c425428b5..6d4572a43f8 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el @@ -869,7 +869,15 @@ See `sh-feature'.") (defconst sh-st-symbol (string-to-syntax "_")) (defconst sh-here-doc-syntax (string-to-syntax "|")) ;; generic string -(defconst sh-here-doc-open-re "<<-?\\s-*\\\\?\\(\\(?:['\"][^'\"]+['\"]\\|\\sw\\)+\\).*\\(\n\\)") +(defconst sh-escaped-line-re + ;; Should match until the real end-of-continued line, but if that is not + ;; possible (because we bump into EOB or the search bound), then we should + ;; match until the search bound. + "\\(?:\\(?:.*[^\\\n]\\)?\\(?:\\\\\\\\\\)*\\\\\n\\)*.*") + +(defconst sh-here-doc-open-re + (concat "<<-?\\s-*\\\\?\\(\\(?:['\"][^'\"]+['\"]\\|\\sw\\)+\\)" + sh-escaped-line-re "\\(\n\\)")) (defvar sh-here-doc-markers nil) (make-variable-buffer-local 'sh-here-doc-markers) @@ -883,7 +891,9 @@ If non-nil INDENTED indicates that the EOF was indented." ;; A rough regexp that should find the opening <].*\\)?\\s|")) + eof-re "['\"]?\\([ \t|;&)<>]" + sh-escaped-line-re + "\\)?\\s|")) ;; A regexp that will find other EOFs. (ere (concat "^" (if indented "[ \t]*") eof-re "\n")) (start (save-excursion @@ -922,7 +932,8 @@ If non-nil INDENTED indicates that the EOF was indented." START is the position of <<. STRING is the actual word used as delimiter (f.ex. \"EOF\"). INDENTED is non-nil if the here document's content (and the EOF mark) can -be indented (i.e. a <<- was used rather than just <<)." +be indented (i.e. a <<- was used rather than just <<). +Point is at the beginning of the next line." (unless (or (memq (char-before start) '(?< ?>)) (sh-in-comment-or-string start)) ;; We're looking at <" + (if (or (nth 5 ppss) (> (count-lines start (point)) 1)) + ;; If the sh-escaped-line-re part of sh-here-doc-re has matched + ;; several lines, make sure we refontify them together. + ;; Furthermore, if (nth 5 ppss) is non-nil (i.e. the \n is + ;; escaped), it means the right \n is actually further down. + ;; Don't bother fixing it now, but place a multiline property so + ;; that when jit-lock-context-* refontifies the rest of the + ;; buffer, it also refontifies the current line with it. + (put-text-property start (point) 'font-lock-multiline t))) sh-here-doc-syntax)) (defun sh-font-lock-here-doc (limit)