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.
This commit is contained in:
Henrik Lissner 2023-09-20 16:19:18 +02:00
parent 36651d6e66
commit c5e387f7b4
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -182,9 +182,18 @@ Updates the date to today."
;;;###autoload ;;;###autoload
(defun +beancount/previous-transaction (&optional count) (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") (interactive "p")
(re-search-backward (let ((pos (point)))
(concat beancount-timestamped-directive-regexp (condition-case e
"\\|" beancount-transaction-regexp) (progn
nil t)) ;; 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))))