From c5e387f7b42be1870565a5ab72f92f03e8a76e4a Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 20 Sep 2023 16:19:18 +0200 Subject: [PATCH] fix(beancount): previous-transaction: jump-to-start behavior To match +beancount/previous-transaction's docstring: this command should jump to the start of the transaction/directive at point first, before jumping to the previous one. Now it does so. It should also return nil if it fails. --- modules/lang/beancount/autoload.el | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/modules/lang/beancount/autoload.el b/modules/lang/beancount/autoload.el index d894a2245..0f162a0c3 100644 --- a/modules/lang/beancount/autoload.el +++ b/modules/lang/beancount/autoload.el @@ -182,9 +182,18 @@ Updates the date to today." ;;;###autoload (defun +beancount/previous-transaction (&optional count) - "Jump to the start of current or previous COUNT-th transaction." + "Jump to the start of current or previous COUNT-th transaction. + +Return non-nil if successful." (interactive "p") - (re-search-backward - (concat beancount-timestamped-directive-regexp - "\\|" beancount-transaction-regexp) - nil t)) + (let ((pos (point))) + (condition-case e + (progn + ;; Ensures "jump to top of current transaction" behavior that is + ;; common for jump-to-previous commands like this in other Emacs modes + ;; (like org-mode). + (or (bolp) (goto-char (eol))) + (re-search-backward + (concat beancount-timestamped-directive-regexp + "\\|" beancount-transaction-regexp))) + ('search-failed (goto-char pos) nil))))