Skip to content

Improve section/order handling #89

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

Merged
merged 3 commits into from
Apr 19, 2015
Merged

Improve section/order handling #89

merged 3 commits into from
Apr 19, 2015

Conversation

dbarnett
Copy link
Contributor

@dbarnett dbarnett commented Apr 5, 2015

Fix having to explicitly declare every built-in section when you use @order and complain if you have redundant definitions for the same section.

Fixes #88.

Also adds a few initial tests to get the ball rolling on #29.

@@ -116,6 +116,18 @@ def __init__(self, section):
'Section {} never defined.'.format(section))


class DuplicateSection(BadStructure):
def __init__(self, section):
super(DuplicateSection, self).__init__(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since (IIRC) Vimdoc now requires Python 3, this can just be super().__init__(.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not worth going out of our way to use the new convention, though.

@malcolmr
Copy link
Member

malcolmr commented Apr 6, 2015

Mostly looks reasonable, but see above.

@@ -60,11 +60,17 @@ def Merge(self, block, namespace=None):
# Overwrite existing section if it's a default.
if block_id not in self.sections or self.sections[block_id].IsDefault():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be simpler if we just invert that check, unless there's some reason we need to be able to support overwriting a default section with another default section?

# Allow overwriting an existing section if it's a default.
if block_id in self.sections and not self.sections[block_id].IsDefault():
  raise error.DuplicateSection(block_id)
self.sections[block_id] = block

(Likewise just below.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually tried that at first, but there's a third case that's missing (default over non-default shouldn't throw error). Just played with a few variations on inverting the check again but didn't find any better version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised we are trying to overwrite non-defaults with defaults, but if that's what we need to do, then this is certainly reasonable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a matter of traversal order. Special flags like plugin[foo] can have a default from one file (plugin/foo.vim) and explicit value declared in another, so we don't know which definition will come last and try to "overwrite" the other.

@malcolmr
Copy link
Member

malcolmr commented Apr 8, 2015

LGTM whichever way you decide to go on the above, btw.

@dbarnett
Copy link
Contributor Author

dbarnett commented Apr 8, 2015

BTW, I'm still updating and addressing the other comments.

I think I do want to get the implicit order into the "natural order" that makes intuitive sense to me, but I'm still having trouble describing the algorithm in plain English. Anyway, I'm adding some tests for the ordering behavior since it's clearly non-trivial. =)

@dbarnett
Copy link
Contributor Author

PTAL. Improved the default ordering and added more tests for it.

# Add any undeclared sections before custom sections, except 'about' which
# comes at the end by default.
section_insertion_idx = 0
order = order[:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to take a copy at the point of assignment above?

i.e.

order = explicit_order[:] or []

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I tried that version first, but it fails for None.

@malcolmr
Copy link
Member

LGTM, thanks (and sorry for the delay).

dbarnett added a commit that referenced this pull request Apr 19, 2015
Improve section/order handling
@dbarnett dbarnett merged commit 8402b70 into master Apr 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More intuitive section/order handling
3 participants