sublime-beancount icon indicating copy to clipboard operation
sublime-beancount copied to clipboard

Add support for account auto completion

Open jmgilman opened this issue 8 years ago • 5 comments

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 avatar Aug 02 '16 00:08 jmgilman

Here was my starting attempt at getting everything into a tree

jmgilman avatar Aug 02 '16 03:08 jmgilman

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 avatar Aug 02 '16 18:08 jmgilman

See: https://github.com/draug3n/sublime-beancount/pull/6

jmgilman avatar Aug 02 '16 21:08 jmgilman

Excellent! I have cut a new version.

norseghost avatar Aug 02 '16 21:08 norseghost

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.

jmgilman avatar Aug 02 '16 23:08 jmgilman