Skip to content
This repository has been archived by the owner on May 25, 2019. It is now read-only.

Do not increase indention inside of comments following ':' #3

Closed
chase opened this issue Dec 12, 2013 · 14 comments
Closed

Do not increase indention inside of comments following ':' #3

chase opened this issue Dec 12, 2013 · 14 comments
Assignees
Labels

Comments

@chase
Copy link
Owner

chase commented Dec 12, 2013

Should be a simple fix, but indentation of comments should remain constant.

This should not occur:
screen shot 2013-12-12 at 1 08 39 am

@benjifisher
Copy link
Contributor

Should we fix the indent function in this project, or should we try to improve the standard YAML indent function?

The YAML indent function already treats comments correctly. The only annoyance I have with it is that it does not indent correctly after - name: foo. Are there other problems with it?

@chase
Copy link
Owner Author

chase commented Nov 15, 2014

Note the picture, it indents the line following the comment since the line ends with :. This behavior shouldn't occur with comments, only YAML keys.

@chase chase self-assigned this Nov 15, 2014
@chase
Copy link
Owner Author

chase commented Nov 15, 2014

The indent file is setup to match common patterns in Ansible, which is what vim-ansible-yaml is all about.
The 7.4 implementation of YAML lagged horribly or was just frustrating to work with for Ansible projects.
One of the primary reasons people adopted this bundle is the fixed indentation. While Ansible is fully YAML compliant, it is a bit of a dialect.

@chase
Copy link
Owner Author

chase commented Nov 15, 2014

@benjifisher What do you mean it doesn't indent correctly after - name: foo?

Most playbooks follow the format of:

- name: Copy file
  file: src=file.txt dest=newfile.txt

Currently it indents after lines like - name: Copy file, would you prefer it not to? If that's the case, please open up another issue and I'll get cracking at it this weekend.

@chase
Copy link
Owner Author

chase commented Nov 15, 2014

Fixed in 7b806f8.

@chase chase closed this as completed Nov 15, 2014
@benjifisher
Copy link
Contributor

Above, I wrote

The YAML indent function already treats comments correctly. The only annoyance I have with it is that it does not indent correctly after - name: foo. Are there other problems with it?

By "The YAML indent function" I meant GetYAMLIndent(), provided by the YAML indent plugin that comes with the standard vim distribution. I meant "it" (three times) to refer to the same indent function.

So I agree that this project (the Ansible indent function, GetAnsibleIndent()) does a better job with that common construct, but my question remains: are there any other problems with the YAML indent function?

@chase
Copy link
Owner Author

chase commented Nov 15, 2014

Sorry, I came off fairly abrasive. I understand what you're saying now. Other than the comment indent issue that I fixed, the only thing I can think of is indenting for multi-line scalar values. That will probably get dealt with alongside #8.

@benjifisher
Copy link
Contributor

No offense taken.

One problem I noticed with the indenting in this project is that it loses indent after a blank line:

tasks:
  - name: Foo
    foo: long line or maybe even a block

  - name: This line gets no indent by default.
    bar: ...

It should be pretty easy to skip over empty lines by using vim's prevnonblank(), which was added for exactly this purpose.

@chase
Copy link
Owner Author

chase commented Nov 16, 2014

I understand how that could be annoying; however, I was trying to use that as a way to not have to manually remove indentation for sub-keys.

How I see it:
In order to remove indentation, depending on where you are in tree of sub-keys, it can take several backspace-presses to get back to the root you want. If you want to keep the indentation, you can just avoid any blank lines until after it is all written out.

At the moment I'm having a hard time thinking up a solution that balances both approaches.

@benjifisher
Copy link
Contributor

Instead of backspace, you can use <C-D> to remove one shiftwidth of space or <C-U>, which removes all indent--much like the current effect of entering a blank line.

I am glad we had this discussion before I pushed a commit "fixing" what I did not like. ;)

@chase
Copy link
Owner Author

chase commented Nov 16, 2014

Thanks to you I just learned another feature of Vim after almost 4 years of constant use, haha. You're a wise man Dr. Fisher.

What we could do is make a global flag for vim-ansible-yaml where your preferred behavior is default unless disabled. Something like let g:ansible_keep_blank_indent = 0, where g:ansible_keep_blank_indent = 1 is default for your behavior.

@benjifisher
Copy link
Contributor

(trying reply-by-email)

Thanks. I am tempted to say that I am knowledgeable rather than wise.
Perhaps it was wise to spend a lot of time reading vim's reference
manual when I first started using it (about 10 or 15 years ago).

Are we agreed that indentation should be based on non-blank lines? If
so, do you want to make the change, or leave it to me?

On Sun, Nov 16, 2014 at 10:17:37AM -0800, Chase Colman wrote:

Thanks to you I just learned another feature of Vim after almost 4 years of constant use, haha. You're a wise man Mr. Fisher.


Reply to this email directly or view it on GitHub:
#3 (comment)

@chase
Copy link
Owner Author

chase commented Nov 16, 2014

I agree that indentation should be based on non-blank lines, yes, so long as the behavior includes the aforementioned flag so people can switch back to the old behavior.
I'll leave that change to you.

As a mentor once told me, wisdom comes from not only experience but the knowledge gained along the journey, related or not. So perhaps a bit of both 👍

@benjifisher
Copy link
Contributor

I changed the indent function as we agreed. At first, I did it on the train, with lousy wifi, and I forgot that you suggested changing the default behavior, so I kept the default behavior. Then I made a second commit to change it.

I updated the README. I may also add doc/ansible.txt when I have time, and I have some further tweaks to the indent function in mind.

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

No branches or pull requests

2 participants