Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Make folding much faster in some cases#743

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fmv1992 merged 1 commit intopython-mode:developfromwilywampa:fold_cache
Mar 9, 2017

Conversation

wilywampa
Copy link
Contributor

Cache the results of Is_opening_folding once per change so it doesn't loop over the same lines multiple times unnecessarily. For autopep8.py for example, this reduced folding time from >10 seconds to near instantaneous.

Cache the results of Is_opening_folding once per change so it doesn'tloop over the same lines multiple times unnecessarily.
@fmv1992fmv1992 merged commit73620c4 intopython-mode:developMar 9, 2017
@fmv1992
Copy link
Contributor

fmv1992 commentedMar 9, 2017
edited
Loading

I have updated the folding code again:https://github.com/fmv1992/python-mode/tree/improve_folding

As the code is here: it does not cover all cases for docstrings and there is also a bug (see below).

Right now I have a solution working but the folding is very slow and it creates more auxiliary functions (that do not have your cacheing solution).

Would you take a look and help me port your solution to this scenario?

Bug sample:

def primitive_name(x, prefixisomoddate=False):    """    Create a primitive name from string x.    Arguments:        x (str): string to be converted to primitive name.    Returns:        str: string converted to primitive name.    """    # Omitted.    basename = re.sub(        '''(?<=_)[^0-9a-zA-Z\_\.]+      # Match all non allowed chars                                        # preceded by underline...            |                           # ... or ...            [^0-9a-zA-Z\_\.]+(?=_)''',  # All non allowed chars followed by                                        # an underline.        '',        basename,        flags=(re.VERBOSE))    # Omitted.    return None

@wilywampa
Copy link
ContributorAuthor

I took a look and you can make it a little faster by doing similar caching on the IsDefinitionStatement function, but the bottleneck is the searchpairpos function and I don't see a way around that. If the results were perfect, I'd say that's probably acceptable in terms of speed. However I noticed a bug soon after testing it out, e.g.

#!/usr/bin/env python"""Automatically formats Python code to conform to the PEP 8 style guide.Fixes that only need be done once can be added by adding a function of the form"fix_<code>(source)" to this module. They should return the fixed source code.These fixes are picked up by apply_global_fixes().Fixes that depend on pycodestyle should be added as methods to FixPEP8. See theclass documentation for more information."""import stufftry:    unicodeexcept NameError:    unicode = str

That example starts a fold at the line with the import statement.

@fmv1992
Copy link
Contributor

That was fortunate/unfortunate. With the old definition regexclass documentation for more information. matched a class definition thus opening a folding. Nevertheless I need to cover the case of a file starting with a she bang or comments/blank lines.

I investigated the nature of folding and they get updated during insert mode. From here on I see two alternatives:

  1. Disable folding during insert mode and refresh the folding with a (possibly costly but complete) folding function.
  2. Go simple and simplify current folding to cover most cases but not all and preserve vim's default of updating the folding during insert mode (creating a perfect folding function would be infeasibly costly with this approach).

Any thoughts?

@wilywampa
Copy link
ContributorAuthor

Personally I use the FastFold plugin to prevent folds updating during insert mode. I suspect a lot of people do the same because updating folds in insert mode is already pretty slow with the current folding function. I don't see any need to update the folds in insert mode so I value correctness over speed to some extent.

@fmv1992
Copy link
Contributor

Thanks. Finding out about this improved my vim experience. Should this be incorporated in pymode? Specially if we invest in the full folding case.
Folding could be updated when saving only (users don't expect this to be lightning fast anyways).

@wilywampa
Copy link
ContributorAuthor

Sorry, I'm not sure what you're asking. Are you asking if I think yourimprove_folding branch should be merged into pymode?

@fmv1992
Copy link
Contributor

No. This branch needs some work anyways. But I think it should be a good idea to let folding be updated only upon saving or other 'rarer' event other than each key you type in insert mode.

@wilywampa
Copy link
ContributorAuthor

I agree that updating less frequently is better but making that a feature of pymode might interfere with autocommands or plugins users have for that purpose. I don't think it's necessary.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@wilywampa@fmv1992

[8]ページ先頭

©2009-2025 Movatter.jp