haml-mode icon indicating copy to clipboard operation
haml-mode copied to clipboard

Apostrophes count as unmatched delimiters

Open anna-is-cute opened this issue 5 years ago • 12 comments

I noticed this in markdown filters, but it appears to happen on any text. Tested on emacs 28.0.50 and haml-mode commit bf5b6c11b1206759d2b28af48765e04882dd1fc4.

%div
  :markdown
    This is an apostrophe: '<>
  %span more elements

If the point is at <>, pressing enter will not indent the next line. Furthermore, trying to type an interpolation or use Ruby past this point will auto-escape further apostrophes.

= func(\'oh no')

or

:markdown
  Inlining a #{func(\'whoops')}!

This is not corrected until a matching apostrophe is added somewhere.

anna-is-cute avatar Jun 22 '20 15:06 anna-is-cute

This doesn't happen in the latest stable Emacs release, so I'd have to guess that it's an Emacs HEAD bug, which is not uncommon.

purcell avatar Jun 22 '20 21:06 purcell

Oh, I didn't even realise I wasn't on stable. Let me compile it real quick and make sure it's fixed.

anna-is-cute avatar Jun 22 '20 21:06 anna-is-cute

That's not to say that some changes won't be needed for Emacs 28, but the release of that stream will probably be in about 15 months. :-)

purcell avatar Jun 22 '20 21:06 purcell

I can confirm this happens on 27.0.91 and 26.3. Could be a conflict, but I'm not sure where to start looking.

anna-is-cute avatar Jun 22 '20 22:06 anna-is-cute

Ah, sorry, I think I misread the issue you were seeing.

Regarding enter and indenting, it would be an anti-pattern for haml-mode to decide that you always wanted ENTER to indent. Emacs provides two commands: newline and newline-and-indent. I do this in my config:

(global-set-key (kbd "RET") 'newline-and-indent)

but you might prefer

(with-eval-after-load 'haml-mode
  (define-key haml-mode-map (kbd "RET") 'newline-and-indent))

Starting from the first snippet you posted, what would be the exact sequence of steps to reproduce the apostrophe issue? I can't seem to do that.

purcell avatar Jun 22 '20 23:06 purcell

Sorry, to be clear, I expect enter to indent because I do have newline-and-indent enabled (this is the normal behaviour I see when apostrophes aren't unmatched).

For me, if I make a new file (C-x C-f something.haml RET), then type %p ', hit enter, then type = a(', the output will look like the below.

%p '
= a(\'

I expect for there not to be a backslash normally. I think that's about as minimal of a test case I can produce.

Packages enabled:

ws-butler haml-mode nhexl-mode lsp-mode rustic sql-indent web-mode dockerfile-mode yaml-mode flycheck base16-theme move-text ## company-quickhelp aggressive-indent smartparens mwim rainbow-delimiters anzu magit-lfs highlight-indent-guides magit ace-window atom-one-dark-theme company neotree

Edit: I think this occurs because of smartparens-mode. I can't say I have this issue with any other mode combined with SP.

Edit 2: The apostrophe escaping is SP, but the indent issue is not.

img 1
img 2

Here highlight-indent-guides shows the problem. If I were to hit enter with the apostrophe escaped, the new line would be indented. If I hit enter without it escaped, the new line is not indented (also reproduced without h-i-g on, but it's a useful indicator).

anna-is-cute avatar Jun 22 '20 23:06 anna-is-cute

If I were to hit enter with the apostrophe escaped, the new line would be indented. If I hit enter without it escaped, the new line is not indented (also reproduced without h-i-g on, but it's a useful indicator).

With point (represented by |) before the apostrophe in your example, after hitting RET (newline-and-indent) I get:

%li
  %a{href: "#returners-hideout"} Returner\|'s Hideout

=>

%li
  %a{href: "#returners-hideout"} Returner\
  |'s Hideout

and

%li
  %a{href: "#returners-hideout"} Returner|'s Hideout

=>

%li
  %a{href: "#returners-hideout"} Returner
  |'s Hideout

So I suspect something else is going on in your config. I suggest you start emacs with -Q, M-x load-file on haml-mode.el, then try to repeat the experiment.

purcell avatar Jun 23 '20 01:06 purcell

Aw, man, I apologise. The point has to be at the end of the line. I didn't realise it was in the wrong place in that screenshot. It was there so I could add the backslash back in.

Without the backslash, hitting enter at the end of the line places the point at the start of the next line. With, it behaves normally.

I can reproduce this by loading haml-mode after emacs -Q.

anna-is-cute avatar Jun 23 '20 01:06 anna-is-cute

The point has to be at the end of the line.

Even then, I get the same behaviour with and without the backslash. And same with emacs -Q, so it's not my local config either.

What haml-mode version do you have? I'm using

;; Package-Version: 20190219.2102

purcell avatar Jun 23 '20 01:06 purcell

%li
  %a{href: "#returners-hideout"} Returner's Hideout<>

That's what I'm testing in emacs -Q with the point at the <>.

haml-mode: 20190219.2102 installed emacs: GNU Emacs 26.3

anna-is-cute avatar Jun 23 '20 01:06 anna-is-cute

M-x newline-and-indent takes me from:

%li
  %a{href: "#returners-hideout"} Returner's Hideout<>|

to

%li
  %a{href: "#returners-hideout"} Returner's Hideout<>
  |

and from

%li
  %a{href: "#returners-hideout"} Returner\'s Hideout<>|

to

%li
  %a{href: "#returners-hideout"} Returner\'s Hideout<>
  |

purcell avatar Jun 23 '20 01:06 purcell

Okay, my bad. I see now where the indent issue comes from, and it was that newline-and-indent was getting turned off for haml-mode.

Any idea why the syntax highlighting breaks after apostrophes? You can see it in the curly braces in the screenshots. Both highlight-indent-guides and some of the syntax highlighting has issues after apostrophes.

anna-is-cute avatar Jun 23 '20 01:06 anna-is-cute