branch: elpa/beancount commit d9ac93fc28799bc523b2c6580c9bc9e80c28da2b Author: Karl Fogel <kfo...@red-bean.com> Commit: Martin Blais <bl...@furius.ca>
Enable easy access to old-style keybindings As per discussion with @blais in PR #35. --- README.org | 12 ++++++++++++ beancount.el | 23 +++++++++++++++++++++++ etc/emacsrc | 11 +++++------ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/README.org b/README.org index dbe12979e4..b488ccf646 100644 --- a/README.org +++ b/README.org @@ -88,3 +88,15 @@ flymake: The =etc/emacsrc= file contains some example configuration for =beancount-mode= and some experiments that may find their way into the main codebase. + +* Keybinding compatibility + +In mid-2023 the default keybindings for many commands in +=beancount-mode= were changed to become compliant with the [[https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Binding-Conventions.html][Emacs +keybinding conventions]]. However, if you are accustomed to the old +keybindings and would prefer to continue using them, just put this +into your Emacs configuration before =beancount.el= is loaded: + +#+begin_src elisp +(setq beancount-mode-old-style-keybindings t) +#+end_src diff --git a/beancount.el b/beancount.el index d5a63c9d80..b6b89df717 100644 --- a/beancount.el +++ b/beancount.el @@ -317,6 +317,19 @@ from the open directive for the relevant account." (defvar beancount-mode-map-prefix [(control c)] "The prefix key used to bind Beancount commands in Emacs") +(defvar beancount-mode-old-style-keybindings nil + "*Set this to non-nil to continue using old-style keybindings. + +In mid-2023, `beancount-mode' changed the keybindings for many of its +commands. This was because the old bindings violated the Emacs +keybinding standards (see section \"Key Binding Conventions\" in the +Emacs Lisp documentation). However, you might be accustomed to the +old bindings and prefer to continue using them; this variable offers a +convenient way to do so. If it is non-nil when `beancount.el' is +loaded, then the old bindings will also be made available. (The new +bindings will be left in place too, since the key sequences they use +are reserved for the mode anyway.)") + (defvar beancount-mode-map (let ((map (make-sparse-keymap)) (p beancount-mode-map-prefix)) @@ -334,6 +347,16 @@ from the open directive for the relevant account." (define-key map (vconcat p [(control i)]) #'beancount-insert-prices) (define-key map (vconcat p [(\;)]) #'beancount-align-to-previous-number) (define-key map (vconcat p [(\:)]) #'beancount-align-numbers) + (when beancount-mode-old-style-keybindings + (define-key map [(control c)(control g)] #'beancount-transaction-clear) + (define-key map [(control c)(l)] #'beancount-check) + (define-key map [(control c)(q)] #'beancount-query) + (define-key map [(control c)(x)] #'beancount-context) + (define-key map [(control c)(k)] #'beancount-linked) + (define-key map [(control c)(r)] #'beancount-region-default) + (define-key map [(control c)(t)] #'beancount-region-value) + (define-key map [(control c)(y)] #'beancount-region-cost) + (define-key map [(control c)(p)] #'beancount-insert-prices)) map)) (defvar beancount-mode-syntax-table diff --git a/etc/emacsrc b/etc/emacsrc index 2dad11a418..6d3f366423 100644 --- a/etc/emacsrc +++ b/etc/emacsrc @@ -46,13 +46,12 @@ (define-key* beancount-mode-map [(control c)(control p)] #'outline-previous-visible-heading) (define-key* beancount-mode-map [(control c)(control u)] #'outline-up-heading) -;; Restore old-style keybindings. +;; Selectively restore old-style keybindings. ;; -;; If you prefer the old (pre-issue-#1) keybindings, you could -;; uncomment some or all of the lines below to selectively restore them. -;; Note that those old bindings don't respect Emacs conventions (see -;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Binding-Conventions.html) -;; which is why they were changed in mid-2023. +;; If you want all the old (pre-issue-#1) keybindings, then set +;; `beancount-mode-old-style-keybindings' in your Emacs configuration +;; to restore them en masse. Or, to restore just certain bindings, +;; uncomment selected lines below: ;; ;; (define-key beancount-mode-map [(control c)(control g)] #'beancount-transaction-clear) ;; (define-key beancount-mode-map [(control c)(l)] #'beancount-check)