Emacs beancount-mode revamp

343 views
Skip to first unread message

Daniele Nicolodi

unread,
Jun 7, 2019, 11:09:59 PM6/7/19
to Beancount
Hello,

I decided to start a new thread about this to give the subject a bit
more visibility.

I have been working on a general revamp of beancount-mode to transform
it into a major mode, mostly to enable better completion behavior. I
open a pull request with the result of this work:

https://bitbucket.org/blais/beancount/pull-requests/115/revamp-beancountel/diff

I think I fixed all bugs reported so far and I would like some more
extended testing. There are some significant changes in behavior:

- It being a major mode now, composing it with org-mode is not possible
anymore. I tried to preserve functionality adding integration with
outline-minor-mode. To add sectioning functionality back you would need
something like

(define-key* beancount-mode-map (key "C-c C-n")
#'outline-next-visible-heading)
(define-key* beancount-mode-map (key "C-c C-p")
#'outline-previous-visible-heading)
(add-hook 'beancount-mode-hook #'outline-minor-mode)

to your Emacs configuration. Recognized headings either start with three
or more semicolons or with asterisks. As per Martin suggestion I
implemented fontification of section headings a la org-mode. Please
report any other missing functionality and I'll see how hard it is to
bring it back.

- "TAB" now either indents, completes, or folds the heading depending on
the context. It works well for me.

- amounts in postings are indented so that the decimal point is at the
52nd column. This can be configured customizing
`beancount-number-alignment-column`. Setting it to 0 will cause the
alignment column to be determined from file content. Postings in
transactions are indented with `beancount-transaction-indent` spaces.

- pressing "RETURN" on causes the current line to be re-indeted. If the
current line is a posting, the amount will be indented as per above.
This behavior is defined by Emacs auto indent mechanism. If you don't
like it you can disable it setting `electric-indent-chars` to nil, for
example like this (untested):

(defun my-disable-electric-indent ()
(setq-local electric-indent-chars nil))
(add-hook 'beancount-mode-hook #'my-disable-electric-indent)

Thank you for testing!

Cheers,
Dan

Martin Blais

unread,
Jun 9, 2019, 8:32:56 AM6/9/19
to Beancount
Merged.
Thank you!


--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/51c98e23-9dec-6b0a-e413-3bca2b7adb8e%40grinta.net.
For more options, visit https://groups.google.com/d/optout.

Martin Blais

unread,
Jun 9, 2019, 9:39:05 AM6/9/19
to Martin Blais, Beancount
FYI. I merged, but just noticed a bug with completions. Completions don't work.
Please hold off updating just now, unless we can resolve this over the next couple of days.

Daniele Nicolodi

unread,
Jun 9, 2019, 2:58:07 PM6/9/19
to bean...@googlegroups.com, Martin Blais
On 09/06/2019 07:38, Martin Blais wrote:
> FYI. I merged, but just noticed a bug with completions. Completions
> don't work. Please hold off updating just now, unless we can resolve
> this over the next couple of days.
I just opened a pull request that fixes the issue

https://bitbucket.org/blais/beancount/pull-requests/121/fix-beancount-insert-account

What did not work was `beancount-insert-account` when
`beancount-use-ido` is true. I don't use either, thus I didn't notice
the problem.

By the way, why do you use `beancount-insert-account` instead of
`completion-at-point` (bound to "TAB")?

Cheers,
Dan

Martin Blais

unread,
Jun 9, 2019, 10:57:01 PM6/9/19
to Daniele Nicolodi, Beancount, Martin Blais
On Sun, Jun 9, 2019 at 2:58 PM Daniele Nicolodi <dan...@grinta.net> wrote:
On 09/06/2019 07:38, Martin Blais wrote:
> FYI. I merged, but just noticed a bug with completions. Completions
> don't work. Please hold off updating just now, unless we can resolve
> this over the next couple of days.
I just opened a pull request that fixes the issue

https://bitbucket.org/blais/beancount/pull-requests/121/fix-beancount-insert-account

What did not work was `beancount-insert-account` when
`beancount-use-ido` is true. I don't use either, thus I didn't notice
the problem.

I tried to disable that at the time but that didn't fix it. 
It works now, thanks for the quick response!
I merged your new PR.
 

By the way, why do you use `beancount-insert-account` instead of
`completion-at-point` (bound to "TAB")?

No idea. I just tried completion-at-point and it doesn't work for me.
beancount-insert-account now works, thank you very much.


 

Cheers,
Dan

Daniele Nicolodi

unread,
Jun 9, 2019, 11:25:34 PM6/9/19
to bean...@googlegroups.com, Martin Blais
On 09/06/2019 20:56, Martin Blais wrote:
> On Sun, Jun 9, 2019 at 2:58 PM Daniele Nicolodi <dan...@grinta.net
>
> By the way, why do you use `beancount-insert-account` instead of
> `completion-at-point` (bound to "TAB")?
>
>
> No idea. I just tried completion-at-point and it doesn't work for me.
> beancount-insert-account now works, thank you very much.

It does not work in the sense that it does not do what it is supposed to
do, or it does not work in the sense that it does not fit in you
workflow? In the first case, I would like to understand why and fix it.

Cheers,
Dan

Martin Blais

unread,
Jun 9, 2019, 11:51:03 PM6/9/19
to Daniele Nicolodi, Beancount, Martin Blais
It doesn't do anything.
I place the cursor after a substring that ought to match an account name, I manually invoke completion-at-point, nothing happens.

 
 

Daniele Nicolodi

unread,
Jun 9, 2019, 11:58:01 PM6/9/19
to Martin Blais, Beancount
On 09/06/2019 21:50, Martin Blais wrote:
> On Sun, Jun 9, 2019 at 11:25 PM Daniele Nicolodi <dan...@grinta.net
> <mailto:dan...@grinta.net>> wrote:
>
> On 09/06/2019 20:56, Martin Blais wrote:
> > On Sun, Jun 9, 2019 at 2:58 PM Daniele Nicolodi
> <dan...@grinta.net <mailto:dan...@grinta.net>
> >
> >     By the way, why do you use `beancount-insert-account` instead of
> >     `completion-at-point` (bound to "TAB")?
> >
> >
> > No idea. I just tried completion-at-point and it doesn't work for me.
> > beancount-insert-account now works, thank you very much.
>
> It does not work in the sense that it does not do what it is supposed to
> do, or it does not work in the sense that it does not fit in you
> workflow?  In the first case, I would like to understand why and fix it.
>
>
> It doesn't do anything.
> I place the cursor after a substring that ought to match an account
> name, I manually invoke completion-at-point, nothing happens.

It works only where beancount-mode knows you may be typing an account
name, and so far this is only as part of a posting in a transaction.
Are you trying to complete an account name in a posting or somewhere
else? I'm planning to lift this limitation but I haven't gotten there yet.

Martin Blais

unread,
Jun 10, 2019, 12:31:51 AM6/10/19
to Daniele Nicolodi, Martin Blais, Beancount
Yes (I was).

 

Daniele Nicolodi

unread,
Jun 10, 2019, 12:58:24 AM6/10/19
to Martin Blais, Beancount
On 09/06/2019 22:31, Martin Blais wrote:
> On Sun, Jun 9, 2019 at 11:58 PM Daniele Nicolodi <dan...@grinta.net
I'm afraid "yes" is not the most clear answer to an A or B question :-)

Do you have a minimal example I can use to reproduce your problem?

Cheers,
Dan


Florian Lindner

unread,
Jun 11, 2019, 4:53:12 AM6/11/19
to bean...@googlegroups.com
Hey,

do you have any plans of adding it to MELPA? I think it will greatly enhance exposure and is a great step, even if it's still beta.

Best,
Florian

Am 08.06.19 um 05:09 schrieb Daniele Nicolodi:

Daniele Nicolodi

unread,
Jun 11, 2019, 1:58:56 PM6/11/19
to bean...@googlegroups.com
Hi Florian,

what I would like at this point is more feedback. I don't think that it
will come with more exposure, especially with more exposure via MELPA.

Nevertheless, I plan to add beancount-mode to MELPA. However, if MELPA
curators are strict about enforcing the code quality requirements
highlighted in the MELPA repository documentation, there is still some
work to do, mostly fixing and adding docstrings and fixing coding style.

Cheers,
Dan

cantas...@gmail.com

unread,
Jun 14, 2019, 6:24:22 PM6/14/19
to Beancount
Ciao Daniele,
I started using your major mode in spacemacs. Good work!
I have some comments:
1) How do you open the beancount file with the tree collapsed?
2) Can you save the tree status?
3) Tree node labels with different asterisks show up all with the same font
4) Is there a better binding than C-c @? It's hard on an American keyboard
5) In org-mode, I could separate labels by adding an extra empty line. The behavior is different here.

Grazie,
Ciao,
Stefano

Daniele Nicolodi

unread,
Jun 14, 2019, 7:09:29 PM6/14/19
to bean...@googlegroups.com
Hi Stefano,

thank you for testing.

On 14/06/2019 16:24, cantas...@gmail.com wrote:
> Ciao Daniele,
> I started using your major mode in spacemacs. Good work!
> I have some comments:
> 1) How do you open the beancount file with the tree collapsed?

You can add

(add-hook 'beancount-mode-hook #'outline-minor-mode)
(add-hook 'beancount-mode-hook (lambda () (outline-hide-sublevels 1)))

or

(defun my-outline-view ()
(outline-minor-mode)
(outline-hide-sublevels 1))
(add-hook 'beancount-mode-hook #'my-outline-view)

to your Emacs configuration.

> 2) Can you save the tree status?

No, outline-minor-mode does not support this. If you would like this
functionality I suggest you to add it to outline-mode. As far as I know,
org-mode does not support this either, and there are few things org-mode
cannot do... :-)

> 3) Tree node labels with different asterisks show up all with the same font

Not for me. There is also a test that verifies that this works as
intended. Do you have a minimal example that shows the problem?

> 4) Is there a better binding than C-c @? It's hard on an American keyboard

beancount-mode does not define that key binding. I guess you are
referring to the defaul outline-minor-mode key prefix. You can change
that through the outline-minor-mode-prefix variable, see the
documentation of outline-mode for details.

> 5) In org-mode, I could separate labels by adding an extra empty line.
> The behavior is different here.

I don't understand what you mean. How is the behavior different?


Cheers,
Dan

Stefano M Canta

unread,
Jun 14, 2019, 7:53:08 PM6/14/19
to bean...@googlegroups.com
I will send a screenshot later!


> 4) Is there a better binding than C-c @? It's hard on an American keyboard

beancount-mode does not define that key binding. I guess you are
referring to the defaul outline-minor-mode key prefix. You can change
that through the outline-minor-mode-prefix variable, see the
documentation of outline-mode for details.
Yes, this is the key binding for the default outline-minor-mode. I will look into that.
Thanks,
 

> 5) In org-mode, I could separate labels by adding an extra empty line.
> The behavior is different here.

I don't understand what you mean. How is the behavior different?

*bla
transaction bla bla

transaction bla bla

*bla2
transaction bla bla


*bla3

When you collapse in org-mode you see:
*bla
*bla2
/// extra empty line
*bla3
 
In beancount-mode you see
*bla
*bla2
*bla3

Thanks!


Cheers,
Dan

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.

Daniele Nicolodi

unread,
Jun 14, 2019, 8:03:53 PM6/14/19
to bean...@googlegroups.com
Hi Stefano,

On 14/06/2019 17:52, Stefano M Canta wrote:
> > 3) Tree node labels with different asterisks show up all with the
> same font
>
> Not for me. There is also a test that verifies that this works as
> intended. Do you have a minimal example that shows the problem?
>
> I will send a screenshot later!

Please don't. Just report the exact content of the buffer that gives you
this problem.

> > 5) In org-mode, I could separate labels by adding an extra empty line.
> > The behavior is different here.
>
> I don't understand what you mean. How is the behavior different?
>
>
> *bla
> transaction bla bla
>
> transaction bla bla
>
> *bla2
> transaction bla bla
>
>
> *bla3
>
> When you collapse in org-mode you see:
> *bla
> *bla2
> /// extra empty line
> *bla3
>  
> In beancount-mode you see
> *bla
> *bla2
> *bla3

This is how outline-minor-mode implements folding. I guess it differs
slightly from what org-mode implements. Given that org-mode is derived
from outline-mode (I think) there may be a way to instruct outline-mode
to do the same. At a quick look I don't see it, however.

Cheers,
Dan

Stefano M Canta

unread,
Jun 15, 2019, 9:23:28 AM6/15/19
to bean...@googlegroups.com
Re: fontify question:

Buffer is called ciao.beancount

* Ciao
** Ciao Ciao

shows up with the same font in the emacs buffer. Again, I am using spacemacs, and I don't know if anything in that configuration conflicts with your major mode.

I do have a second question: when entering transactions, the account search (C-c ') does not list the best match at the top. For example, As:Tr should map to Assets:Transfer in my config file, but the first choice that comes up is Assets:Immaterial. The same happens for many other accounts.

Thank you
Stefano

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.

Daniele Nicolodi

unread,
Jun 15, 2019, 12:11:48 PM6/15/19
to bean...@googlegroups.com
On 15/06/2019 07:22, Stefano M Canta wrote:
> Re: fontify question:
>
> Buffer is called ciao.beancount
>
> * Ciao
> ** Ciao Ciao
>
> shows up with the same font in the emacs buffer. Again, I am using
> spacemacs, and I don't know if anything in that configuration conflicts
> with your major mode.

This works for me.

Are you using the latest beancount.el from the mercurial repository?

Are you setting the outline-regexp buffer local variable to something
different than what beancount-mode sets it? You can verify it with C-h v
outline-regexp. It's value should be "\\(;;;+\\|\\*+\\)".

Which faces are associated with the "Ciao" and "Ciao Ciao" portions of
the buffer? You can check it looking at the proposed completion for the
M-x describe-face command when the point is on either portion of the
buffer. They should be org-level-0 and org-level-1 respectively.

> I do have a second question: when entering transactions, the account
> search (C-c ') does not list the best match at the top. For example,
> As:Tr should map to Assets:Transfer in my config file, but the first
> choice that comes up is Assets:Immaterial. The same happens for many
> other accounts.

This depends on the completion method you use. With the default
beancount-use-ido set to t it works as expected here. It may be that
spaceemacs configures the completion engines in unusual ways.
Unfortunately, those are quite intricate and I would not know where to
look to understand where the difference in behavior comes from.

That said, one of the reasons I had to work on beancount-mode was to
make completion on TAB work. If you insert As:Tr and then pres TAB the
you should obtain the correct completion, without going through C-c '.

Cheers,
Dan

frs....@gmail.com

unread,
Jul 7, 2019, 11:27:00 PM7/7/19
to Beancount
Sorry, I'm a bit late to the party, but....

I made the mistake of updating my beancount source, and now my emacs config is completely frelled.  I found this thread, so I presume this update is the reason.  I don't mean to complain about progress, but at the moment I'm blown out of the water and would like advice as to how to proceed: limp back to some previous source tree, or alter my config to meet the future head-on?

Whenever I first visit my beancount accounts file, I'm immediately slammed into the debugger:

progn: Wrong number of arguments: ((beancount-mode-abbrev-table t) nil "A mode for Beancount files.

\\{beancount-mode-map}

This mode runs the hook `beancount-mode-hook', as the final or penultimate step
during initialization." (interactive) (progn (make-local-variable (quote delay-mode-hooks)) (let ((delay-mode-hooks t)) (kill-all-local-variables) (setq major-mode (quote beancount-mode)) (setq mode-name "Beancount") nil (use-local-map beancount-mode-map) (set-syntax-table beancount-mode-syntax-table) (setq local-abbrev-table beancount-mode-abbrev-table) (set (make-local-variable (quote paragraph-ignore-fill-prefix)) t) ...)) (run-mode-hooks (quote beancount-mode-hook))), 1

I read talk of a Melpa package -- is that so?  I don't see beancount listed in stable.melpa.org or melpa.org.



Frederick Noon

unread,
Jul 7, 2019, 11:33:13 PM7/7/19
to Beancount
Addendum: my current emacs config looks like this:

  (add-to-list 'load-path "~/enc/src/bitbucket/blais/beancount/editors/emacs")
  ;;(add-to-list '
load-path "/usr/local/elisp")
 
(require 'beancount)
  (add-to-list '
auto-mode-alist '("\\.bct\\'" . org-mode))  ; set major mode
  (add-hook 'find-file-hook  ; set minor mode
            (lambda ()
              (when (string= (file-name-extension buffer-file-name) "
bct")
                (beancount-mode +1))))



Frederick Noon

unread,
Jul 7, 2019, 11:42:52 PM7/7/19
to Beancount
I see beancount-mode is now a major mode?  So I amended my config to the following:

  (add-to-list 'load-path "~/enc/src/bitbucket/blais/beancount/editors/emacs")
  ;;(add-to-list '
load-path "/usr/local/elisp")
 
(require
'beancount)
  (add-to-list '
auto-mode-alist '("\\.bct\\'" . beancount-mode))  ; set major mode

Now no more debugger.  TAB only performs completion, however, which doesn't help a lot -- but I'll start on the other config changes mentioned at the start of the thread to try getting around that.  Baby steps....

Frederick Noon

unread,
Jul 8, 2019, 12:16:47 AM7/8/19
to Beancount
I've gotten section folding to work again, but only by manually invoking 'outline-minor-mode'.  Shouldn't that be engaged by 'beancount-mode'?  Or am I not "doing it right"?

Samuel W. Flint

unread,
Jul 8, 2019, 1:36:55 PM7/8/19
to bean...@googlegroups.com
>>>>> Frederick Noon writes:

FN> I've gotten section folding to work again, but only by manually
FN> invoking 'outline-minor-mode'. Shouldn't that be engaged by
FN> 'beancount-mode'? Or am I not "doing it right"?

How? I've tried activating with the hook, or doing it manually and I
can't seem to get it to work?

Thanks,

Sam

--
Samuel W. Flint
4096R/FA13D704
(F50D 862B 4F65 5943 A8C2 EF0E 86C9 3E7A FA13 D704)
λs.(s s) λs.(s s)

Daniele Nicolodi

unread,
Jul 9, 2019, 4:51:54 PM7/9/19
to bean...@googlegroups.com
Why should it? Pairing the outline folding facility with beancount-mode
via org-mode was optional before, and I feel it should stay that way.
The recommended way to have the outline folding facility with
beancount-mode is to do enable outline-minor-mode from beancount-mode-hook:

(add-hook 'beancount-mode-hook #'outline-minor-mode)

as detailed in the very first mail in this thread.

PS: Sending four emails that could be very well summarized with "I am
too lazy to read the very same email I'm answering too, but I feel
entitled to complain" is not the best way to motivate people to invest
their free time in helping you.

Best,
Dan

Daniele Nicolodi

unread,
Jul 9, 2019, 4:53:17 PM7/9/19
to bean...@googlegroups.com
On 08/07/2019 11:36, Samuel W. Flint wrote:
>>>>>> Frederick Noon writes:
>
> FN> I've gotten section folding to work again, but only by manually
> FN> invoking 'outline-minor-mode'. Shouldn't that be engaged by
> FN> 'beancount-mode'? Or am I not "doing it right"?
>
> How? I've tried activating with the hook, or doing it manually and I
> can't seem to get it to work?

Other that saying that it works for me and others, this is not an
actionable bug report. Sorry.

Cheers,
Dan

Frederick Noon

unread,
Jul 9, 2019, 7:28:12 PM7/9/19
to Beancount
On Tuesday, July 9, 2019 at 1:51:54 PM UTC-7, Daniele Nicolodi wrote:
Why should it?  Pairing the outline folding facility with beancount-mode
via org-mode was optional before, and I feel it should stay that way.

I guess I see your point.  I'm nearly always in org-mode, and have always used the beancount minor mode in that context.  So I suppose my thinking was inverted.
 
The recommended way to have the outline folding facility with
beancount-mode is to do enable outline-minor-mode from beancount-mode-hook:

Now I know why you set things up that way.  I thought this might still be "work in progress" mode, but that's really the expected config.
 
PS: Sending four emails that could be very well summarized with "I am
too lazy to read the very same email I'm answering too, but I feel
entitled to complain" is not the best way to motivate people to invest
their free time in helping you.

Sorry I'm not the beta tester you were hoping for.  Still, thanks for straightening things out.

Samuel W. Flint

unread,
Jul 9, 2019, 9:02:31 PM7/9/19
to bean...@googlegroups.com
>>>>> Daniele Nicolodi writes:

DN> On 08/07/2019 11:36, Samuel W. Flint wrote:
>>>>>>> Frederick Noon writes:
>>
FN> I've gotten section folding to work again, but only by manually
FN> invoking 'outline-minor-mode'. Shouldn't that be engaged by
FN> 'beancount-mode'? Or am I not "doing it right"?
>>
>> How? I've tried activating with the hook, or doing it manually
>> and I can't seem to get it to work?

DN> Other that saying that it works for me and others, this is not
DN> an actionable bug report. Sorry.

Agreed. I was asking Frederick what he did. Turns out
outline-minor-mode was interacting with an old version of outshine.
Haven't used outshine in long enough that I stopped using it and all is
well, however, I wonder if it would still cause the same problem.

DN> Cheers, Dan

Daniele Nicolodi

unread,
Jul 10, 2019, 7:32:23 AM7/10/19
to bean...@googlegroups.com
On 09/07/2019 19:02, Samuel W. Flint wrote:
>>>>>> Daniele Nicolodi writes:
>
> DN> On 08/07/2019 11:36, Samuel W. Flint wrote:
> >>>>>>> Frederick Noon writes:
> >>
> FN> I've gotten section folding to work again, but only by manually
> FN> invoking 'outline-minor-mode'. Shouldn't that be engaged by
> FN> 'beancount-mode'? Or am I not "doing it right"?
> >>
> >> How? I've tried activating with the hook, or doing it manually
> >> and I can't seem to get it to work?
>
> DN> Other that saying that it works for me and others, this is not
> DN> an actionable bug report. Sorry.
>
> Agreed. I was asking Frederick what he did. Turns out
> outline-minor-mode was interacting with an old version of outshine.
> Haven't used outshine in long enough that I stopped using it and all is
> well, however, I wonder if it would still cause the same problem.

I would say that if outshine is doing something that breaks
outline-minor-mode the bug is in outshine and it may be worth reporting
to the outshine developers (if you can verify that the bug is still
present in the latest version).

Best,
Dan

Daniele Nicolodi

unread,
Jul 11, 2019, 12:14:19 PM7/11/19
to bean...@googlegroups.com
It is not matter of beta testing, but of basic etiquette. I would have
hoped for this to be universally recognized. I don't have anything to
loose in ignoring further communication from you that follows a similar
pattern.

Best,
Dan
Reply all
Reply to author
Forward
0 new messages