glynnforrest / salt-mode

Emacs major mode for Salt States

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Comments "#" ending in colon ":" trigger indentation

nickgarber opened this issue · comments

Hiya,

When I add a commented-out line ending in a colon while using Salt-mode the buffer will indent everything, (comment and non-comment) that follows it.

I think the simplest, perhaps best, case would be to disable the trailing ":" indentation rule for lines starting with a comment character.

Thanks for the mode, it's AWESOME!

Thanks for the report and kind words @nickgarber!

Can you provide a small snippet that shows the offending behaviour please? I'm struggling to reproduce this. I suspect it'll have something to do with yaml-mode indentation, which salt-mode is based on.

Sure! I've taken to using a metadata block at the beginning of each SLS as a summary for colleagues. When it's empty it might look like this...


##_META:
##

Inside this meta-block, I include some high-level description, commented out ('##'), in YAML format. Because it's commented out I'd expect it to not follow the indentation of a non-commented block, but it does.

In the above example, when I auto-indent the buffer it ends up looking like this...


##_META:
  ##

Here's a simple example with some data filled-in...

##_META:
##  purpose: join new machines to the domain
##  suitability:
##    - G@os_family:RedHat and G@osmajorrelease:7
##    - G@deployenv:dev
##  todo:
##    - test for the presence of required info: either dutyinfo grains or cv1-permitted name
##

When I auto-indent a buffer containing this content, it ends up looking like this...

##_META:
  ##  purpose: join new machines to the domain
  ##  suitability:
    ##    - G@os_family:RedHat and G@osmajorrelease:7
    ##    - G@deployenv:dev
    ##  todo:
      ##    - test for the presence of required info: either dutyinfo grains or cv1-permitted name
      ##

It's simple to fix but has the effect of discouraging buffer-wide actions that I'd otherwise consider normal and beneficial.

After reading your update it does seem that this is likely to originate from the underlying yaml-mode. I'll look into that more and you may feel free to close the ticket if you'd like.

Thanks for your response!

Thanks for the detailed writeup. Yes, unfortunately yaml-mode makes buffer-wide actions fraught with peril and wildly unpredictable. Even a simple file like this:

one:
    somekey:
        - something
    otherkey:
        - something

will transform into something crazy when you indent the entire buffer.

Yaml-mode's indentation can 'cycle', meaning that hitting tab at the cursor will indent it at different places:

one:
    somekey:
        - something|
one:
    somekey:
    - something|
one:
    somekey:
- something|

Yaml itself has a hideously complex specification, so I'm not sure yaml-mode can do much to change its current indenting behaviour.

However, what you're experiencing inside comments definitely seems like a bug to me.

A comment like this stays the same after indenting the whole buffer:

# some comment
# lots of things
# more info

but adding a : causes a whole world of pain:

    # some comment:
        # lots of things
        # more info

I've filed a yaml-mode issue, see yoshiki/yaml-mode#65.

That's very kind of you @glynnforrest, I appreciate it! I'll follow that issue and close this one.
Cheers!