all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nicholas Sushkin <nsushkin@openfinance.com>
Cc: emacs-devel@gnu.org
Subject: Re: shell mode syntax higlighting problem with here documents
Date: Thu, 20 Oct 2005 17:12:39 -0400	[thread overview]
Message-ID: <200510201712.39665.nsushkin@openfinance.com> (raw)
In-Reply-To: <87oe5konp2.fsf-monnier+gnu.emacs.bug@gnu.org>

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 <<EOF back.
>  	 (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 <<STRING, so we add "^STRING$" to the syntactic
> @@ -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

  parent reply	other threads:[~2005-10-20 21:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.11923.1129741494.20277.bug-gnu-emacs@gnu.org>
2005-10-20  3:48 ` shell mode syntax higlighting problem with here documents Stefan Monnier
2005-10-20  5:12   ` Nicholas Sushkin
2005-10-20 21:12   ` Nicholas Sushkin [this message]
2005-10-20 21:22     ` Nick Roberts
2005-10-20 21:56       ` Nicholas Sushkin
2005-10-21  3:14         ` Stefan Monnier
2005-10-21 17:03           ` Nicholas Sushkin
2005-10-21 17:42             ` Stefan Monnier
2005-10-21 19:03               ` Nicholas Sushkin
2005-10-19 17:04 Nicholas Sushkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200510201712.39665.nsushkin@openfinance.com \
    --to=nsushkin@openfinance.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.