beancount.el vs emacs keybinding conventions

218 views
Skip to first unread message

Stefano Zacchiroli

unread,
Nov 12, 2016, 2:56:35 PM11/12/16
to bean...@googlegroups.com
Heya,
I've started using beancount.el to do my Beancount editing. It has
great features --- for which I'm super grateful :-)) --- but I couldn't
help a feeling that the mode got in my way, clashing with almost all my
personal mode-independent Emacs keybindings.

In the beginning I thought this was just a coincidence, and that I was
very unlucky, but I recently realized it is not. beancount.el seems to
consistently use lot of "C-c <letter>" keybindings, which are supposed
to be reserved for users and should not be used by Emacs modes or Lisp
programs. Here's a quote from Emacs documentation about key binding
conventions[^]:

> Don't define C-c letter as a key in Lisp programs. Sequences consisting
> of C-c and a letter (either upper or lower case) are reserved for users;
> they are the only sequences reserved for users, so do not block them.
>
> Changing all the Emacs major modes to respect this convention was a
> lot of work; abandoning this convention would make that work go to
> waste, and inconvenience users. Please comply with it.

[^]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Binding-Conventions.html

According to the same document either C-c followed by punctuation /
symbols (if beancount.el is to remain a minor mode) or C-c followed by
control characters / digits (if it is to graduate to a major mode) would
be more appropriate.

Martin: any chance we could convince you to adopt these conventions for
the default keybindings of beancount.el? If yes, I'd be happy to file a
proposal as a patch in the issue tracker. But at the time I guess that
if the keybindings are to be changed to something else, you would want
to pick it yourself what that something else is.

With many thanks in advance for considering,
Cheers.
--
Stefano Zacchiroli . za...@upsilon.cc . upsilon.cc/zack . . o . . . o . o
Computer Science Professor . CTO Software Heritage . . . . . o . . . o o
Former Debian Project Leader . OSI Board Director . . . o o o . . . o .
« the first rule of tautology club is the first rule of tautology club »

Martin Blais

unread,
Nov 12, 2016, 3:00:56 PM11/12/16
to Beancount
I don't have a super strong preference, the problem is just finding a free single-sequence prefix these days.
I've heard about the GNU prescription but in practice I've witnessed other packages using the C-c key and it seems like it depends a bit on how ominously package implementors have taken the word of GNU to the letter :-)

(Stefan will probably want to weigh in at this point.)

I think what I could do for now is change the code so you can set your own favorite prefix, and start looking for another one.


 

Martin Blais

unread,
Nov 12, 2016, 3:24:14 PM11/12/16
to Beancount
https://bitbucket.org/blais/beancount/commits/b969f5f75b699707d50e52d686248997e5786655

Use it like this:
(setq beancount-mode-map-prefix [(control x)(control a)])  ;; Or whatever you prefer
(require 'beancount)



Stefano Zacchiroli

unread,
Nov 12, 2016, 4:28:24 PM11/12/16
to bean...@googlegroups.com
On Sat, Nov 12, 2016 at 03:23:51PM -0500, Martin Blais wrote:
> https://bitbucket.org/blais/beancount/commits/b969f5f75b699707d50e52d686248997e5786655
>
> Use it like this:
> (setq beancount-mode-map-prefix [(control x)(control a)]) ;; Or whatever
> you prefer
> (require 'beancount)

Thanks Martin!, this is definitely good enough.
(And C-x C-a looks indeed like a reasonable and available choice.)

Stefan Monnier

unread,
Nov 12, 2016, 6:04:52 PM11/12/16
to bean...@googlegroups.com
> I've heard about the GNU prescription but in practice I've witnessed other
> packages using the C-c key and it seems like it depends a bit on how
> ominously package implementors have taken the word of GNU to the letter :-)

Note that the issue is not with "the C-c key". It's with "C-c
<letter>", where `letter` doesn't mean "any event" but "a plain
un-modified letter" as in "something that matches [[:alpha:]]".

It's true that a fair number of modes use "C-c <letter>", against the
conventions, but I think it's still a minority.

> (Stefan will probably want to weigh in at this point.)

Hi Martin!


Stefan "who thinks beancount-mode should be a major-mode"

Stefano Zacchiroli

unread,
Nov 13, 2016, 3:05:16 AM11/13/16
to bean...@googlegroups.com
On Sat, Nov 12, 2016 at 06:03:58PM -0500, Stefan Monnier wrote:
> > (Stefan will probably want to weigh in at this point.)

Chiming in here: yeah, I've been thinking about it too. In abstract
terms it would probably make more sense but I'm also very sympathetic to
Martin's use case of using org-mode together with beancount-mode (which
I believe it's why he wants to keep it a minor-mode, right Martin?).

Is there any other way of achieving the same? e.g., maybe by refactoring
the code so that you've both a major mode and a minor mode (maybe
org-mode specific) coming from the same code base? Are there other
examples of similar needs in the Emacs ecosystem?

Martin Blais

unread,
Nov 13, 2016, 2:39:15 PM11/13/16
to Beancount
On Sun, Nov 13, 2016 at 3:04 AM, Stefano Zacchiroli <za...@upsilon.cc> wrote:
On Sat, Nov 12, 2016 at 06:03:58PM -0500, Stefan Monnier wrote:
> > (Stefan will probably want to weigh in at this point.)

Chiming in here: yeah, I've been thinking about it too. In abstract
terms it would probably make more sense but I'm also very sympathetic to
Martin's use case of using org-mode together with beancount-mode (which
I believe it's why he wants to keep it a minor-mode, right Martin?).

That's the only reason. If we could find a way to inject outline capability (folding sections) like in org-mode I'd be fine having it as a major-mode. The thing is, for those very large files, org-mode/outline is not just a fancy nice to have, it's a "must-have".


Is there any other way of achieving the same? e.g., maybe by refactoring
the code so that you've both a major mode and a minor mode (maybe
org-mode specific) coming from the same code base? Are there other
examples of similar needs in the Emacs ecosystem?

No idea.
Stefan is the expert here, I just mumble some elisp and sometimes it works.

Stefan Monnier

unread,
Nov 14, 2016, 9:43:09 AM11/14/16
to bean...@googlegroups.com
> Chiming in here: yeah, I've been thinking about it too. In abstract
> terms it would probably make more sense but I'm also very sympathetic to
> Martin's use case of using org-mode together with beancount-mode (which
> I believe it's why he wants to keep it a minor-mode, right Martin?).

It shouldn't be too hard to make a major mode which uses Org's code for
outlining functionality.

You could simply start by making the mode derive from org-mode.


Stefan

Jeffrey Brent McBeth

unread,
Nov 14, 2016, 10:44:23 AM11/14/16
to bean...@googlegroups.com
Org-mode already has a minor mode to support this called orgstruct-mode
> --
> 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/jwvpolym8e0.fsf-monnier%2Bgmane.comp.finance.beancount%40gnu.org.
> For more options, visit https://groups.google.com/d/optout.

--
"The man who does not read good books has no advantage over
the man who cannot read them."
-- not Mark Twain, maybe a southen librarian in 1910

Stefano Zacchiroli

unread,
Nov 14, 2016, 12:11:19 PM11/14/16
to bean...@googlegroups.com
On Mon, Nov 14, 2016 at 10:44:16AM -0500, Jeffrey Brent McBeth wrote:
> Org-mode already has a minor mode to support this called orgstruct-mode

Really nice!

I confirm it works together with current beancount.el, even has a
companion minor mode. The only annoying behavior I've encountered thus
far is that there seems to be no obvious way to have every sections
automatically folded when you open the file.

I guess I just haven't found the right knob yet...

Martin Blais

unread,
Nov 20, 2016, 2:58:07 PM11/20/16
to Beancount
Just tried it myself, inspired by this excitement; but... orgstruct-mode does not appear to operate similarly to org-mode. I cannot use the regular bindings to move up and down visible headings (it purports to, but it fails), and while folding single sections works, the functions to fold the entire file don't appear to work the same, and the multiple levels of headings don't appear differentiated by color.

So... my quick test of this is really quite disappointing. Maybe there's a way to make it as good as org-mode, but that would take a substantial amount of time. If someone has the energy and time, go for it, I'd love to try it. I don't have the time to do this myself.


--
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+unsubscribe@googlegroups.com.

To post to this group, send email to bean...@googlegroups.com.

Simon Michael

unread,
Nov 20, 2016, 6:09:47 PM11/20/16
to bean...@googlegroups.com
Not sure if you noticed: at least some of the org functions only work
when point is on an org node.
>> email to beancount+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages