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

Add support for account auto completion #5

Open
jmgilman opened this issue Aug 2, 2016 · 5 comments
Open

Add support for account auto completion #5

jmgilman opened this issue Aug 2, 2016 · 5 comments

Comments

@jmgilman
Copy link
Contributor

jmgilman commented Aug 2, 2016

Wanted to start a discussion thread on this much needed feature. As far as I can tell there's two options, both which are unfortunately hard to implement:

  1. Bundle beancount and all of its dependencies within the package and then use the module to parse the current file and search for accounts. This has two major problems: there's quite a few dependencies for beancount (that also have local software dependencies) and when the plugin is called for autocomplete it will fail if the file happens to not be a valid beancount file at the time of calling it (which I believe will be the case almost every time).
  2. Attempt to manipulate the file using core python functions. This doesn't have the issues like above, but it also completely requires reinventing the wheel in terms of having to parse accounts and then search across them.

Since I think option 1 is a no go in my opinion, I started on option 2 but was quickly inundated with the complexities of trying to create a tree structure of all accounts. Perhaps we can get the author of beancount to provide some pointers here.

If I get some better prototypes working I will share them here.

@jmgilman
Copy link
Contributor Author

jmgilman commented Aug 2, 2016

Here was my starting attempt at getting everything into a tree

@jmgilman
Copy link
Contributor Author

jmgilman commented Aug 2, 2016

After playing around, I came across a not so discussed setting in Sublime Text that I think actually solves this problem without a plugin. To test it, do the following:

  • Open up a Beancount file
  • Go to Sublime Text -> Preferences -> Settings - More -> Syntax Specific - User
  • In that file, place the following:
{
    "word_separators": "./\\()\"'-,.;<>~!@#$%^&*|+=[]{}`~?",
}

How it works: In Sublime Text there's what we call "word separators". Basically these are characters that Sublime Text will use to determine when a word starts and when it ends. By default, the colon character is a word separator. That's why when you're typing in Sublime Text the auto-complete will sometimes prompt you with accounts that don't belong to the particular account you're typing in (because it doesn't associate the entire account name as one string).

In the above configuration I removed the colon as a word separator. Now when I'm typing the autocomplete recognizes the entire account string and will even provide the nice fuzzy search across multiple account names.

When you save this setting file it creates a beancount.sublime-settings file in the user directory. I have not been able to test if putting this file in the package directory will also enable the setting. If I can confirm this works, then I will submit a pull request with the new file so that this "auto completion" is included by default in the package.

@jmgilman
Copy link
Contributor Author

jmgilman commented Aug 2, 2016

See: #6

@norseghost
Copy link
Owner

Excellent! I have cut a new version.

@jmgilman
Copy link
Contributor Author

jmgilman commented Aug 2, 2016

Awesome, thanks! I think we can close this issue out now unless someone has the desire to improve this even further with an actual plugin.

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

No branches or pull requests

2 participants