narendraj9 / hledger-mode Goto Github PK
View Code? Open in Web Editor NEWAn Emacs major mode for Hledger
License: GNU General Public License v3.0
An Emacs major mode for Hledger
License: GNU General Public License v3.0
emacs: 26.1
hledger-mode: master branch
In config:
(setq hledger-currency-string "$")
In ~/.hledger.journal
2018/08/10 Income
assets:bank:checking $ 20
income:salary
And run M-x hledger-run-command RET overall
This results in:
Report : 15 Jul 2018 - 15 Aug 2018
══════════════════════════════════=
Income Statement 2018/07/15-2018/08/14
|| 2018/07/15-2018/08/14
===============++=======================
Revenues ||
---------------++-----------------------
income:salary || $ 20
---------------++-----------------------
|| $ 20
===============++=======================
Expenses ||
---------------++-----------------------
---------------++-----------------------
||
===============++=======================
Net: || $ 20
Balance changes in 2018/07/15-2018/08/14:
|| 2018/07/15-2018/08/14 Average
===============++================================
income:salary || $ -20 $ -20
---------------++--------------------------------
|| $ -20 $ -20
Expanded Running Report
=======================
Balance changes in 2018/07/15-2018/08/14:
|| 2018/07/15-2018/08/14 Average
==============++================================
assets || $ 20 $ 20
bank || $ 20 $ 20
checking || $ 20 $ 20
--------------++--------------------------------
|| $ 20 $ 20
and the error: let*: Wrong type argument: number-or-marker-p, $
Report : 15 Jul 2018 - 15 Aug 2018
══════════════════════════════════=
╔══════════════════════════════════════╦══════════════════════════════════════════╗
Emergency Fund Ratio: inf Savings Ratio: 1.00
Current Ratio: inf Average Income: ₹ 2/month
Debt Ratio: 0.00 Average Expenses: ₹ 0/month
──────────────────────────────────────────────────────────────────
Liquid Assets: ₹ 20.00 Total Assets: ₹ 20.00
Liabilities: ₹ 0.00 Net Worth: ₹ 20.00
──────────────────────────────────────────────────────────────────
Years to retirement: -inf Retiring at: -inf
Age:26 Life Expectancy: 80
╚══════════════════════════════════════╩══════════════════════════════════════════╝
════════════════════════════════════════════════════════════════════════════════
• Your liquid assets would last nan and total assets nan with this lifestyle.
• Your liquid assets are inf times your liabilities/debt.
• 0.00% of your total assets are borrowed.
• For the past one year, you have been saving 100.00% of your average income.
• Your assets would roughly increase by ₹ 100 in the next 5 years making your
net worth ₹ 120. If compounded every 4 months at 4.0% per annum, your net
worth would become ₹ 130.
════════════════════════════════════════════════════════════════════════════════
Income Statement 2018/07/15-2018/08/14
|| 2018/07/15-2018/08/14
===============++=======================
Revenues ||
---------------++-----------------------
income:salary || ₹ 20
---------------++-----------------------
|| ₹ 20
===============++=======================
Expenses ||
---------------++-----------------------
---------------++-----------------------
||
===============++=======================
Net: || ₹ 20
Balance changes in 2018/07/15-2018/08/14:
|| 2018/07/15-2018/08/14 Average
===============++================================
income:salary || ₹ -20 ₹ -20
---------------++--------------------------------
|| ₹ -20 ₹ -20
Expanded Running Report
=======================
Balance changes in 2018/07/15-2018/08/14:
|| 2018/07/15-2018/08/14 Average
==============++================================
assets || ₹ 20 ₹ 20
bank || ₹ 20 ₹ 20
checking || ₹ 20 ₹ 20
--------------++--------------------------------
|| ₹ 20 ₹ 20
and no errors.
This worked fine with other currency symbols: £, €, ¤, ¢, ¥, "randomstring".
Currently, hledger-reports.el is a mess. It makes sense to rethink reports here. It's the only file that interacts with hledger binary.
I have found myself entering the same kinds of entries again and again. So, it makes sense to group these entries : a set of account names with a normalized description by the frequencies they occur with. One can then make good suggestions for the account names based on fuzzy matches with the partial description string.
Hi, I couldn't figure out how to edit your wiki. I added some instructions here. https://github.com/paynito/hledger-mode/wiki/Getting-Started-on-Mac---Spacemacs
It makes sense to have a metric that tells you how much time it would take you to be rich enough to retire.
When I attempt to use the exclamation point as a status mark (pending transactions), the next line (the first account adjustment) does not indent until I fill it in completely.
You can work around this; once you finish typing the first line (including the number) and press <Tab>, the line will then indent properly.
i am using the currency symbol ( INR ) to append after value.
my ledger file is three years old.
setting (setq hledger-currency-string "INR") is prepending INR before value.
can we change this behaviour ?
expected :
2021-12-20 purchase of rice
Assets:Current:Cash 20.00 INR
what is happening :
2021-12-20 purchase of rice
Assets:Current:Cash INR 20.00
I can easily modify the indent functions to ask for a date when the user hits tab more than once. I can use org-reschedule
which in turn uses org-read-date
. It would be more convenient if the user could type at (point)
itself and the resulting date would be shown in an overlay in front of the input text and hitting [Enter]
would just insert the date in the right format.
In ledger-mode, if user presses M-q, it will clean up the "paragraph", that is, it will realign amounts, etc.
Would this be a good feature for hledger-mode? Users may be bringing in data added by other ledger data entry tools (like my mobile app), and may want to clean up their data once they're back at desktop. (I would put amounts all at the same column in my app, but currently, the view does not parse and present transactions in a formatted way, so I try to input the columns to a minimum for now.)
Hello,
I initiated Emacs in a clean state using emacs -Q
. While executing the test cases, I observed that not all of them passed as expected.
@shivjm: Can you provide some insights regarding these errors? (#53)
Selector: t
Passed: 9
Failed: 5 (5 unexpected)
Skipped: 0
Total: 14/14
Started at: 2023-09-10 17:21:16+0200
Finished.
Finished at: 2023-09-10 17:21:16+0200
F.........FFFF
F ert-hledger-account-bounds-is-correct
(void-function hledger-bounds-of-account-at-point)
F hledger-accounts-should-not-update
With ‘hledger-invalidate-completions’ set to ‘on-idle’, saving or
(void-function hledger-mode)
F hledger-accounts-should-update-on-edit
With ‘hledger-invalidate-completions’ set to ‘(on-idle
(void-function hledger-mode)
F hledger-accounts-should-update-on-save
With ‘hledger-invalidate-completions’ set to ‘(on-idle
(void-function hledger-mode)
F hledger-date-manipulation-works
(void-function hledger-add-days-to-entry-date)
There are many places that call hledger, and for the most part, the arguments are a simple string. This usually isn’t an issue, but, for instance, running M-x hledger-run-command RET balance RET some account with spaces produces something along the lines of hledger balance some account with spaces
, i.e. four separate arguments to the balance
command. It would be good to consistently escape user input (unless it’s specifying hledger options, of course).
Sort of related to #50.
This happens mainly because of division by 0. The numbers are then passed on to truncate
that fails. Fix this.
I just created flycheck-hledger. You might want to try it and/or reference it in your README.
Thanks for maintaining this!
As a user of ledger-mode, I'm curious how they compare. What's the same, what can I do in one but not the other, why did you start this one etc. Could you add this to the docs ?
Currently, most of the state of the major-mode is stored in global variables. This state is relevant only until the next report is generated post which it is updated. It makes sense to store this information in a more structured from in the buffer itself using text properties.
Mainly report generating code is redundant at a lot of places. It needs to be refactored.
Study Hledger implementation and see the amount of effort that would be required to implement an Emacs Lisp alternative. I would want to do this to remove dependency on hledger
and better integration with Emacs.
When using hledger-mode
with company support, I noticed that the hledger-accounts-cache
was never filled up. I traced the issue back to this:
When running (hledger-update-accounts)
on a journal file, it throws Wrong type argument: stringp, nil
. A buffer must be specified for the function to work, even though it's marked as an optional argument, and is used without an argument throughout the code. Therefore, hledger-accounts-cache
is never set.
I guess the function was supposed to default to the current-buffer
if no argument is provided, but it currently runs the function only if the buffer is nil
or equal to current-buffer
:
hledger-mode/hledger-defuns.el
Lines 346 to 349 in 1b9c652
It’ll work fine if the accounts have been cached, but will fail the next time hledger-mode attempts to update the list. I think it would make sense to add -I to hledger accounts. I’m not aware of any other checks that are enabled by default; I would assume that only malformed data prevents autocompletion otherwise.
Every time a tab event occurs on a line with an account, the monetary symbol appears at the end (in my case, it's the US dollar sign: "$"). By itself, it's nothing major, and can be convenient. However, when using Yasnippet, every line seems to act as if the tab is pressed. For the main line (with the transaction name and date), this does not seem to be a problem.
Additionally, every account line will cause the monetary symbol to swap (the symbol is added to lines that don't have it, and removed from lines that do have it). Again, no big deal, in the snippet, I just place the symbol on those lines that I do not want the symbol to appear, and all is fine.
However, the problem happens when I have a line that, in the yasnippet, ends with a placeholder and a monetary symbol. When the symbol is removed, it is replaced with nothing, and Yasnippet complains because it can't find the placeholder anymore, because the search regex ends with [:space:], and that space was removed.
I'm thinking that it might be helpful to, when removing a monetary symbol using a tab event, at least put a space in its place, to ensure such regular expressions don't fail.
Hi there,
center-text-for-reading in your use-package definition does nothing here, and I cannot find it on the web. This is maybe something just in your config? Maybe it shouldn't be here in the readme, it can cause problems.
But maybe you can just paste your definition for that here? I'm curios about it.
//Martin
Something I keep wishing for is a way to edit the command line that hledger-run-command
runs. It would be useful if one could call it with a prefix argument to see and edit the final command before it was run, similarly to what M-x grep
presents.
One alternative I can think of is to build a transient-based interface for hledger commands. This would probably be even more helpful, but also a big undertaking.
Hi, I need some advice on making auto-completion work with Corfu. Corfu, unlike Company uses the built-in cap functions. I can see that the docs mention using Company and auto-complete, but it's not clear how to make it work with Corfu. Any advice will be appreciated. Thanks.
Hi,
thank you for your package. I think the project lacks some documentation. For example:
hello. I tried your keybinding
(global-set-key (kbd "C-c j") 'hledger-run-command)
it produces this error
command-execute: Wrong type argument: commandp, hledger-run-command
same error if I use
(spacemacs/set-leader-keys "hbb" 'hledger-run-command)
(spacemacs/set-leader-keys "hbb" 'hledger-balancesheet)
or
(spacemacs/set-leader-keys "hbb" 'hledger-balancesheet*)
Thank you for this great project. I find it useful.
Hi,
I maintain budget accounts and would appreciate seeing a report showing them. With ledger-mode
, I configure ledger-reports
with an item such as:
("Budget" "%(binary) -f %(ledger-file) balance --empty --sort account ^Budget and not \\(Unbudgeted\\)")
Is there a way to configure user-specific reports?
i have installed hledger-mode using straight package manager.
i am getting the following error :
error: Could not find package hledger-input. Updating recipe repositories: (org-elpa melpa gnu-elpa-mirror el-get emacsmirror-mirror) with ‘straight-pull-recipe-repositories’ may fix this
straight-pull-recipe-repositories
is not able to fix this error.
there is no error with removing following bit from configuration.
(use-package hledger-input
:load-path "straight/build/hledger-mode/"
:bind (("C-c e" . hledger-capture)
:map hledger-input-mode-map
("C-c C-b" . popup-balance-at-point))
:preface
(defun popup-balance-at-point ()
"Show balance for account at point in a popup."
(interactive)
(if-let ((account (thing-at-point 'hledger-account)))
(message (hledger-shell-command-to-string (format " balance -N %s "
account)))
(message "No account at point")))
:config
(setq hledger-input-buffer-height 20)
(add-hook 'hledger-input-post-commit-hook #'hledger-show-new-balances)
(add-hook 'hledger-input-mode-hook #'auto-fill-mode)
(add-hook 'hledger-input-mode-hook
(lambda ()
one more difficulty is with entering account names, as company mode is not working in hledger-mode.
my company-mode configuration looks like this :
;; company mode
(use-package company
:diminish company-mode
:hook ((prog-mode LaTeX-mode latex-mode org-mode ledger-mode hledger-mode) . company-mode)
:bind
(:map company-active-map
([tab] . smarter-tab-to-complete)
("TAB" . smarter-tab-to-complete))
:custom
(company-minimum-prefix-length 1)
(company-tooltip-align-annotations t)
(company-require-match 'never)
;; Don't use company in the following modes
(company-global-modes '(not shell-mode eaf-mode))
is there any configuration change needed for using with straight package manager ?
Hi,
I was able to setup Hledger in Emacs and it works fine. But as the journals will contain all my financials wanted to encrypt them so I did a basic setup as described in [1]. Hledger capture works fine for me but none of the other functions in Emacs work. I get an error that hldeger is failing to encrypt. I did skim through the hledger code and it seems like encryption using GPG is not supported out-of-the-box for reports. Wanted to check if my understanding is right? If yes, can you provide some pointers on how I could fix this?
[1]: https://pzel.name/2016/07/18/Encrypted-hledger-with-emacs-and-gnupg.html
Thanks,
-Sumit
Hi there,
I'm just creating this issue as a reminder to myself to add a major-mode for hledger rules files. Atm I'm just hacking some font-lock rules with .dir-locals but expanding this into a full major-mode is a goal.
(font-lock-add-keywords
nil
`((,(rx bol (* space) (group "#" (* any)) eol)
1 font-lock-comment-face t)
(,(rx bol (* space)
(group word-start
(or "if"
"fields"
"date-format"
"skip")
word-end))
1 font-lock-keyword-face t)
(,(rx bol (* space)
(group word-start
(or "date"
"reference"
"description"
(and (or "date"
"amount"
"account"
"comment")
(one-or-more digit)))
word-end))
1 font-lock-builtin-face t)
(,(rx (group word-start "%" (one-or-more alnum) word-end))
1 font-lock-variable-name-face t)))
I've installed hledger
in ~/<user>/.local/bin/
:
$ hledger --version
hledger 1.15.2
$ where hledger
/home/<user>/.local/bin/hledger
Doing hledger-run-command
gave me zsh:1: command not found:
in the report buffer.
Here is the relevant configuration :
(add-to-list 'exec-path "/home/<user>/.local/bin")
;; ...
(use-package hledger-mode
:ensure t
:mode ("\\.journal\\'" "\\.hledger\\'")
:init
(setq hledger-jfile "~/personal/accounting.journal")
and the weird part is if I eval-expression
(executable-find "hledger")
I get
"/home/<user>/.local/bin/hledger"
If I move all hledger-*
binaries in /usr/bin
, all command work fine. I'm missing something,
how should I specify the binary's path ?
It would be great if we can make entering various commodities easier for the user, maybe through a list of completions or cycling through the commodities that have been entered so far. Currently, there is support only for the hledger-currency-string
. Hitting tab after an account name causes the insertion of the currency symbol defined that is hledger-currency-string
.
Please provide a stable package version available on melpa-stable.
The probably cause for the issues is: https://lists.gnu.org/archive/html/bug-gnu-emacs/2016-08/msg00031.html
There's no hledger-mode-pkg.el file. IIUC Melpa creates one for us but it seems broken (see also melpa/melpa#4680).
That's the generated file:
(define-package "hledger-mode" "20170402.1110" "A mode for writing journal entries for hledger."
'((emacs "24.4")
(popup "0.5.3")
(async "1.9")
(htmlize "1.47"))
:url "https://github.com/narendraj9/hledger-mode.git" :keywords
'("data"))
Note how it does not mention emlib, which is required by hledger-suggest.el. This leads to a compilation failure when installing hledger-mode without emlib installed.
I believe a proper -pkg.el file should be committed to the repo.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.