Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ansible_unindent_after_newline to intelligently un-indent to the correct parent block #78

Open
rootwyrm opened this issue Jun 30, 2019 · 4 comments

Comments

@rootwyrm
Copy link

This one is really frustrating me.

Load the plugin how you like (I use pathogen still), then:

let g:ansible_unindent_after_newline = 1
let g:ansible_attribute_highlight = "ob"
let g:ansible_extra_keywords_highlight = 1
let g:ansible_normal_keywords_highlight = 'Constant'
let g:ansible_with_keywords_highlight = 'Constant'
let g:ansible_template_syntaxes = { '*.rb.j2': 'ruby' }

Create a new tasks/main.yml and start making some magic, only to find it breaking in the most frustrating ways.

---
- name: This is just a demo
  hosts: "{{ target|default('localhost') }}"

  tasks:
    - name: Show the brokenness.
      ## Prevent fail-into
      when: (ansible_facts['distribution'] == "bananabread")
      template:
        src: some.j2
        dest: /usr/local/etc/some.conf
        - name: This line did not indent even close to correctly.

# vim:ft=yaml.ansible:

But we have let g:ansible_unindent_after_newline = 1 so this should fix it, right? Wrong.

---
- name: This is just a demo
  hosts: "{{ target|default('localhost') }}"

  tasks:
    - name: Show the brokenness.
      ## Prevent fail-into
      when: (ansible_facts['distribution'] == "bananabread")
      template:
        src: some.j2
        dest: /usr/local/etc/some.conf

- name: Well this line has no business being all the way over here.

# vim:ft=yaml.ansible:

More obnoxiously, this is unfixable without killing the plugin. Fix the broken indent, assuming it will reset position, and it does not. Instead it re-indents the whole thing back to 0 and just keeps breaking it over and over.

@pearofducks
Copy link
Owner

I'm happy to accept a pull request for this, but I'm not interested in solving this problem.

@pearofducks pearofducks changed the title ansible_unindent_after_newline unindenting too aggressively Improve ansible_unindent_after_newline to intelligently un-indent to the correct parent block Jun 30, 2019
@albgus
Copy link

albgus commented Aug 19, 2019

Would it be possible to simply implement an option to disable the indention from this plugin? I find the standard yaml indention logic to be enough but it would still be nice to have the highlighting from this plugin while not having to work around the indention.

@savchenko
Copy link

Would it be possible to simply implement an option to disable the indention from this plugin?

Sounds like a reasonable balance between cost of implementation and end-effect.
@pearofducks , would you accept pull request for such option?

@pearofducks
Copy link
Owner

This should already be doable with standard Vim config support. No support should be needed from this plugin to reset indentexpr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants