From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: shell mode syntax higlighting problem with here documents Date: Wed, 19 Oct 2005 23:48:49 -0400 Message-ID: <87oe5konp2.fsf-monnier+gnu.emacs.bug@gnu.org> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1129780233 15228 80.91.229.2 (20 Oct 2005 03:50:33 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 20 Oct 2005 03:50:33 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Oct 20 05:50:29 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1ESRQN-0006w6-QQ for ged-emacs-devel@m.gmane.org; Thu, 20 Oct 2005 05:49:04 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ESRQN-0007Ou-6x for ged-emacs-devel@m.gmane.org; Wed, 19 Oct 2005 23:49:03 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1ESRQD-0007ME-Lk for emacs-devel@gnu.org; Wed, 19 Oct 2005 23:48:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1ESRQC-0007LY-VA for emacs-devel@gnu.org; Wed, 19 Oct 2005 23:48:53 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ESRQC-0007LH-P6 for emacs-devel@gnu.org; Wed, 19 Oct 2005 23:48:52 -0400 Original-Received: from [209.226.175.93] (helo=tomts36-srv.bellnexxia.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1ESRQC-000158-Q5 for emacs-devel@gnu.org; Wed, 19 Oct 2005 23:48:52 -0400 Original-Received: from alfajor ([70.48.83.21]) by tomts36-srv.bellnexxia.net (InterMail vM.5.01.06.10 201-253-122-130-110-20040306) with ESMTP id <20051020034849.EEFH16985.tomts36-srv.bellnexxia.net@alfajor>; Wed, 19 Oct 2005 23:48:49 -0400 Original-Received: by alfajor (Postfix, from userid 1000) id 10516D72AD; Wed, 19 Oct 2005 23:48:49 -0400 (EDT) Original-To: Nicholas Sushkin In-Reply-To: (Nicholas Sushkin's message of "Wed, 19 Oct 2005 13:04:33 -0400") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:44372 Archived-At: > #!/bin/bash > cat << EOF | \ > tee -a bug.txt > This is a test case for a bug in bash shell mode text highlighting > EOF If people who hack on SH scripts with lots of heredoc thingies could try the patch below, it would help. It's relative to the Emacs-CVS code. It seems "safe" and appears to do the right thing with the above example, but I'd like to get some positive feedback before installing it, Stefan --- orig/lisp/progmodes/sh-script.el +++ mod/lisp/progmodes/sh-script.el @@ -869,7 +869,18 @@ (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 + (concat + "\\(?:" + ;; First the real regexp. + "\\(?:.*[^\\\n]\\)?\\(?:\\(?:\\\\\\\\\\)*\\\\\n\\(?:.*[^\\\n]\\)?\\)*" + ;; Then a failsafe fallback: in case the search boundary prevents us from + ;; finding the actual end of line. + "\\|.*\\)")) + +(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 +894,9 @@ ;; 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 +935,8 @@ 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 (> (count-lines start (point)) 1) (nth 5 ppss)) + ;; 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 we haven't actually found the right \n. + ;; 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)