all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Carlos Pita <carlosjosepita@gmail.com>
Cc: occitan@esperanto.org, 18380@debbugs.gnu.org
Subject: bug#18380: 24.3.93; sh-script multiline quoted subshell wreaks havoc with indentation
Date: Tue, 02 Sep 2014 20:39:36 -0400	[thread overview]
Message-ID: <jwv4mwp3626.fsf-monnier+emacsbugs@gnu.org> (raw)
In-Reply-To: <877g1n1kjf.fsf@gmail.com> (Carlos Pita's message of "Mon, 01 Sep 2014 11:29:24 -0300")

> This will see the { as quoted:
> "$(echo  "{")"
>
> while this will not:
>
> "$(echo
>    "{")"

Actually, it depends: sometimes it will sometimes it won't :-(

> after this line indentation is broken as Emacs thinks there is an
> unclosed open brace.
>
> The problem with multiline quoted subshells is more general, as
> remarked by this comment in sh-script.el:
>
>   ;; 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 flaky.

Indeed, the problem you show is the direct result of the problem alluded
to in the above comment.  I installed the patch below which seems to help.


        Stefan


=== modified file 'lisp/progmodes/sh-script.el'
--- lisp/progmodes/sh-script.el	2014-07-21 01:41:59 +0000
+++ lisp/progmodes/sh-script.el	2014-09-03 00:37:50 +0000
@@ -1051,13 +1051,11 @@
   "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 flaky.
   (when (eq ?\" (nth 3 (syntax-ppss))) ; Check we matched an opening quote.
     ;; bingo we have a $( or a ` inside a ""
     (let (;; `state' can be: double-quote, backquote, code.
           (state (if (eq (char-before) ?`) 'backquote 'code))
+          (startpos (point))
           ;; Stacked states in the context.
           (states '(double-quote)))
       (while (and state (progn (skip-chars-forward "^'\\\\\"`$()" limit)
@@ -1088,7 +1086,12 @@
                  (`double-quote nil)
                  (_ (setq state (pop states)))))
           (_ (error "Internal error in sh-font-lock-quoted-subshell")))
-        (forward-char 1)))))
+        (forward-char 1))
+      (when (< startpos (line-beginning-position))
+        (put-text-property startpos (point) 'syntax-multiline t)
+        (add-hook 'syntax-propertize-extend-region-functions
+                  'syntax-propertize-multiline nil t))
+      )))
 
 
 (defun sh-is-quoted-p (pos)






  reply	other threads:[~2014-09-03  0:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-01 14:29 bug#18380: 24.3.93; sh-script multiline quoted subshell wreaks havoc with indentation Carlos Pita
2014-09-03  0:39 ` Stefan Monnier [this message]
2019-09-30  2:54 ` Stefan Kangas

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=jwv4mwp3626.fsf-monnier+emacsbugs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=18380@debbugs.gnu.org \
    --cc=carlosjosepita@gmail.com \
    --cc=occitan@esperanto.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.