Skip to content

Commit

Permalink
Only shift date under point
Browse files Browse the repository at this point in the history
  • Loading branch information
vkazanov committed May 17, 2024
1 parent eb57e84 commit 751201c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions beancount.el
Original file line number Diff line number Diff line change
Expand Up @@ -887,13 +887,16 @@ DAYS can negative or positive."
"%Y-%m-%d"
(time-add today (days-to-time days))))

(defun beancount--shift-date-at-line (days)
"Shift the date in the current line by a specified number of DAYS."
(defun beancount--shift-date-at-point (days)
"Shift the date under point by a specified number of DAYS."
(let* ((date-regexp beancount-date-regexp)
(current-line (thing-at-point 'line t))
(date (if (string-match date-regexp current-line)
(pos (- (point) (pos-bol)))
(date (if (and (string-match date-regexp current-line)
(>= pos (match-beginning 0))
(<= pos (match-end 0)))
(match-string 0 current-line)
(user-error "No date found in current line")))
(user-error "No date found under point")))
(newdate (beancount--shift-date (date-to-time date) days)))
(save-excursion
(beginning-of-line)
Expand All @@ -904,13 +907,13 @@ DAYS can negative or positive."
"Increase the date in the current line by one day.
With prefix ARG, change that many days."
(interactive "p" beancount-mode)
(beancount--shift-date-at-line (or days 1)))
(beancount--shift-date-at-point (or days 1)))

(defun beancount-date-down-day (&optional days)
"Decrease the date in the current line by one day.
With prefix ARG, change that many days."
(interactive "p" beancount-mode)
(beancount--shift-date-at-line (- (or days 1))))
(beancount--shift-date-at-point (- (or days 1))))

(defvar beancount-install-dir nil
"Directory in which Beancount's source is located.
Expand Down

0 comments on commit 751201c

Please sign in to comment.