diff --git a/README.md b/README.md index 24619a9..8f9a830 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,15 @@ LedgerTools is a [Ledger CLI](ledger-cli.org) pluggin for Sublime Text. +![LedgerTools demo](demo/demo.gif) + Features: - Syntax definition - Auto-align the amounts - Makes payee and account insertion easier -- Auto-detection of non-cleared entries. +- Auto-detection of non-cleared entries +- Automatic transaction notification ## Installation @@ -19,7 +22,48 @@ Other solution: just clone it to the Package directory. git clone https://github.com/etienne-monier/LedgerTools.git ~/.config/sublime_text/Packages/LedgerTools ``` -Once the package is installed, one should run `Package Control: Satisfy Dependencies` to install [`parsimonious`](https://github.com/erikrose/parsimonious) which is a dependency. +## Some words about how I maintain my journal + +I dislike mixing all user transactions with all the payee, account, automatic transaction definitions. What I usually do is to define a main file `main.ledger` whose content is + +``` +; This is main.ledger + +include definitions.ledger +include current.ledger +``` + +In the same directory, I then have two other files `definition.ledger` and `current.ledger`. The first one keeps all commands and automatic transactions. + +``` +; This is definition.ledger + +account First account +account Second account + +payee A payee + +tag aTag + += /aReGeX/ + First account 10 EUR + Second account -10 EUR +``` + +The second one keeps all user transactions. + +``` +; This is current.ledger + +04/02/2021 A payee + First account 10 EUR + Second account -10 EUR +``` + +**This distinction is important as the program looks for account, payee and automatic transaction definitions in `definition.ledger` to work. This file location should be given in the package settings**. + +Note: This does not mean you can not mix the two files in a single one, but it means you have to define this single file as the definition file in the settings. + ## Auto-align the amount @@ -45,11 +89,11 @@ account Expenses:Food payee The Amazing French Restaurant ``` -Then, you only have to specify the filename as the `definition_filename` setting. Then, two default keamaps are defined: `Ctrl+Shift+a` to insert an account at the cursor position and `Ctrl+Shift+z` to insert a payee. A quick panel oppens and you can search whatever you want by typing some words. +Then, you only have to specify the filename as the `definition_filename` setting. Then, two default keymaps are defined: `Ctrl+Shift+a` to insert an account at the cursor position and `Ctrl+Shift+z` to insert a payee. A quick panel oppens and you can search whatever you want by typing some words. ### What about virtual account? -If, like me, you also use Ledger to budget (e.g. [You Need A Budget](https://www.youneedabudget.com/)), then you may have virtual accounts liked to budget. +If, like me, you also use Ledger to budget (e.g. [You Need A Budget](https://www.youneedabudget.com/)), then you may have virtual accounts associated to budget. ``` account Budget:Books @@ -87,27 +131,34 @@ To explain this, consider a list of entries such as ``` In this list, the first two entries are denoted cleared with a star placed before the payee. The last one (Forno Gusto) is not cleared. This can mean whatever you want. In my case, I use it to denote the transactions that do not appear yet on my online bank register so that, when I type + ``` ledger balance Assets --real --cleared ``` + (notice the `--cleared` option), the Forno Gusto transaction is not taken into account and I get the same balance as my bank. That helps me to be sure not to make a mistake. When the transaction appear in my bank balance, I simply add a star. **Meanwhile, the pluggin highlights the entry which has not been cleared.** This helps to see imediatly which entries are still pending. **Notes:** 1. By default, Ledger consider all entries, even those which are not cleared. As a consequence, + ``` ledger balance Assets --real ``` + would take the Forno Gusto transaction into account. -2. If you don't whant this feature, please modify the `Ledger.sublime-syntax file` following lines: +2. If you don't whant this feature, please modify the `Ledger.sublime-syntax file` following lines (70-72): + ``` # Non-cleared entry - match: '\s+({{payee}})' captures: 1: invalid ``` + to + ``` # Non-cleared entry - match: '\s+({{payee}})' @@ -115,6 +166,18 @@ to 1: markup.italic.desc ``` +## Automatic transaction notification + +Again, I usually use automatic transaction to maintain my Budget. For that, I define a lots of them in my definition file, like + +``` += /Depenses:Food/ + [Equity:Budgets] 1 + [Assets:Budgets:Food] -1 +``` + +The user transactions defined in the `current.ledger` file hiding an automatic transaction is notified with the hidden transaction detail. + ## Author and license This pluggin has been written by [Etienne Monier](https://etienne-monier.github.io/). diff --git a/autom_transaction_gutter.py b/autom_transaction_gutter.py index 09a03f9..20222bb 100644 --- a/autom_transaction_gutter.py +++ b/autom_transaction_gutter.py @@ -756,12 +756,6 @@ class AutomaticTransactionGutterUpdateOnSave(sublime_plugin.ViewEventListener): update the gutters that show hidden automatic transactions. """ - # align thread - thread = None - # listen actions - registered_actions = ["insert", "left_delete", "right_delete", - "delete_word", "paste", "cut"] - def update_autom_trans_info(self): # If not a ledger file, exit. @@ -784,37 +778,8 @@ def update_autom_trans_info(self): "autom_tran", GUTTER_LINES, "markup.warning", "dot", sublime.HIDDEN) - def on_modified(self): - - # If not a ledger file - if not utils.is_ledger_file(self.view): - return - - if not utils.get_settings().get('automatic_amount_alignment'): - return - - # Do not process scratch or widget files - if self.view.is_scratch() or self.view.settings().get('is_widget'): - return - - # Get the last executed command - cmdhist = self.view.command_history(0) - # If that' not a command to listen, return. - if cmdhist[0] not in self.registered_actions: - return - - # Default delay - delay = 1 - - # We need to define a timer to add delay. - if self.thread: - self.thread.cancel() - - self.thread = threading.Timer( - delay, - self.update_autom_trans_info - ) - self.thread.start() + def on_post_save(self): + self.update_autom_trans_info() def on_load(self): self.update_autom_trans_info() diff --git a/demo/demo.gif b/demo/demo.gif new file mode 100644 index 0000000..e4bd55f Binary files /dev/null and b/demo/demo.gif differ diff --git a/tests/gif.ledger b/tests/gif.ledger new file mode 100644 index 0000000..0af7952 --- /dev/null +++ b/tests/gif.ledger @@ -0,0 +1,24 @@ +; This is a comment +# this is too +% also +| ... +* final comment + +account Equity: Budget +account Assets:Current +account Assets:Budget:Food +account Expenses:Food + +payee A first payee +payee A second payee +payee A third payee + += /Expenses:Food/ + Equity: Budget 1 + Assets:Budget:Food -1 + +04/02/2021 A second payee + Expenses:Food 10 EUR + Assets:Current + +; Let's save ! \ No newline at end of file