uncomment-region in beancount emacs (minor) mode

50 views
Skip to first unread message

Andreas Reuleaux

unread,
Apr 2, 2018, 7:48:43 PM4/2/18
to bean...@googlegroups.com
I am long term ledger user - and having seen beancount recommended
recently over ledger, thought I would give it a try.

Thus I have installed beancount with pip3 and in addition downloaded
the source code from the mercurial repo with

hg clone https://bitbucket.org/blais/beancount

and adjusted my emacs config accordingly, such that beancount
gets loaded when opening a .beancount file

(add-to-list 'load-path ".../beancount/editors/emacs")
(require 'beancount)
(add-to-list 'auto-mode-alist '("\\.beancount$" . beancount-mode))

One of the things that I do frequently (in any emacs mode /
programming environment for that matter), is mark a few lines,
comment them out with comment-region, and maybe later: uncomment them.
I have handy keystrokes for comment-region and uncomment-region.

Now in beancount (minor) mode (with org major mode), I can comment out
a region, say a transaction from the example file, I mark those lines:

2016-01-04 * "BANK FEES" "Monthly bank fee"
Assets:US:BofA:Checking -4.00 USD
Expenses:Financial:Fees 4.00 USD

and comment-region gives me

;; 2016-01-04 * "BANK FEES" "Monthly bank fee"
;; Assets:US:BofA:Checking -4.00 USD
;; Expenses:Financial:Fees 4.00 USD

fine. however when I try to uncomment (mark the lines again,
uncomment-region), they are just commented out one further level:

;; ;; 2016-01-04 * "BANK FEES" "Monthly bank fee"
;; ;; Assets:US:BofA:Checking -4.00 USD
;; ;; Expenses:Financial:Fees 4.00 USD

which is not what I wanted. is it just me experiencing this behaviour?

thanks,

-Andreas

Martin Blais

unread,
Apr 2, 2018, 9:16:17 PM4/2/18
to Beancount
This is a known bug in the Emacs config.
It's getting on own nerves regularly actually, just haven't had time to dig into fixing this.
(If you have Emacs chops and this is easy for you a patch is always appreciated.)



--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/87po3hw4o8.fsf%40a-rx.info.
For more options, visit https://groups.google.com/d/optout.

Andreas Reuleaux

unread,
Apr 2, 2018, 11:19:18 PM4/2/18
to bean...@googlegroups.com
Martin Blais <bl...@furius.ca> writes:

> This is a known bug in the Emacs config.
> It's getting on own nerves regularly actually, just haven't had time to dig
> into fixing this.
> (If you have Emacs chops and this is easy for you a patch is always
> appreciated.)
>

well tbanks, and as far as I can see: it has to do with the special
combination of org-mode + beancount-mode: I don't get this strange
behaviour of uncomment-region when specifying
-*- mode: fundamental mode: beancount-*-
eg.


thus as a workaround (not good enough for a patch really, but it does
remedy the situation for me):

before that I had comment-region/uncomment-region defined on C-f3/C-f4

(define-key (current-global-map) (kbd "C-<f4>") 'comment-region)
(define-key (current-global-map) (kbd "C-<f3>") 'uncomment-region)

now I am switching to emacs-lisp-mode temporarily and back to
org+beancount mode, I am using emacs-lisp-mode here, rather than say fundamental-mode,
because it has the same comment-style ";; " (otherwise I get asked:
what comment style?), thus now I have:


(define-key (current-global-map) (kbd "C-<f4>") 'comment-region)
(define-key (current-global-map) (kbd "C-<f3>") 'special-uncomment-region)


(defun special-uncomment-region (beg end &optional arg)
"blah blah..."
;; same params as in orig uncomment-region
(interactive "*r\nP")

(cond

(( and (eq major-mode 'org-mode) (bound-and-true-p beancount-mode) )
(progn

(message "org/beancount mode, special uncomment-region")

(emacs-lisp-mode)
(uncomment-region beg end arg)
(org-mode)
(beancount-mode)
)
)


;; default case
(t
(ignore nil)
(uncomment-region beg end arg)
)


) ;; cond

)


maybe this is helpful for someone ? - until the real cause has been found
and a patch created.

-Andreas

Stefan Monnier

unread,
Apr 3, 2018, 8:09:09 AM4/3/18
to Martin Blais, Beancount
Martin Blais <bl...@furius.ca> writes:

> This is a known bug in the Emacs config.
> It's getting on own nerves regularly actually, just haven't had time to dig
> into fixing this.

Try to add this to beancount-mode:

;; Org-mode sets both of these to `org-comment-or-uncomment-region',
;; which doesn't know about our ";" comments.
(kill-local-variable 'comment-region-function)
(kill-local-variable 'uncomment-region-function)


-- Stefan

Martin Blais

unread,
Apr 3, 2018, 7:58:47 PM4/3/18
to Stefan Monnier, Martin Blais, Beancount
Reply all
Reply to author
Forward
0 new messages