From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicholas Sushkin Newsgroups: gmane.emacs.devel Subject: Re: shell mode syntax higlighting problem with here documents Date: Thu, 20 Oct 2005 17:12:39 -0400 Organization: Open Finance Message-ID: <200510201712.39665.nsushkin@openfinance.com> References: <87oe5konp2.fsf-monnier+gnu.emacs.bug@gnu.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1129842933 27898 80.91.229.2 (20 Oct 2005 21:15:33 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 20 Oct 2005 21:15: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 23:15:24 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EShii-0001Rj-DV for ged-emacs-devel@m.gmane.org; Thu, 20 Oct 2005 23:13:04 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EShih-00054e-PK for ged-emacs-devel@m.gmane.org; Thu, 20 Oct 2005 17:13:03 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EShiX-00054T-4P for emacs-devel@gnu.org; Thu, 20 Oct 2005 17:12:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EShiV-00053w-NJ for emacs-devel@gnu.org; Thu, 20 Oct 2005 17:12:52 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EShiV-00053t-KN for emacs-devel@gnu.org; Thu, 20 Oct 2005 17:12:51 -0400 Original-Received: from [128.241.244.171] (helo=mail.openfinance.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EShiV-0005ap-Gk for emacs-devel@gnu.org; Thu, 20 Oct 2005 17:12:51 -0400 Original-Received: by mail.openfinance.com (Postfix, from userid 889) id 6208B7FCA4; Thu, 20 Oct 2005 16:45:00 -0400 (EDT) Original-Received: by hidden.hop; Original-To: Stefan Monnier User-Agent: KMail/1.8 In-Reply-To: <87oe5konp2.fsf-monnier+gnu.emacs.bug@gnu.org> Content-Disposition: inline X-VirusRpt: No viruses found in message 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:44447 Archived-At: Stefan, I am trying to test in Emacs 21.3.1 your revision 1.169, but getting "Invalid escape character syntax" in the statement below. Is my emacs too old or it's really a bug? Thanks (defvar sh-skeleton-pair-default-alist '((?( _ ?)) (?\)) (?[ ?\s _ ?\s ?]) (?\]) (?{ _ ?}) (?\})) "Value to use for `skeleton-pair-default-alist' in Shell-Script mode.") On Wednesday 19 October 2005 23:48, Stefan Monnier wrote: > > #!/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 < (sre (concat "<<\\(-?\\)\\s-*['\"\\]?" > ;; Use \s| to cheaply check it's an open-heredoc. > - eof-re "['\"]?\\([ \t|;&)<>].*\\)?\\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 < @@ -933,6 +947,20 @@ > (setq sh-here-doc-re > (concat sh-here-doc-open-re "\\|^\\([ \t]*\\)" > (regexp-opt sh-here-doc-markers t) "\\(\n\\)")))) > + (let ((ppss (save-excursion (syntax-ppss (1- (point)))))) > + (if (nth 4 ppss) > + ;; The \n not only starts the heredoc but also closes a > comment. + ;; Let's close the comment just before the \n. > + (put-text-property (1- (point)) (point) 'syntax-table '(12))) > ;">" + (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) -- Nicholas Sushkin, Senior Software Engineer Open Finance, Chelsea Piers Pier 62 Suite 316, New York NY 10011 Tel +1 646 723 2790 Fax +1 646 723 2789 nsushkin@openfinance.com