From 9ca754b34d939f06b7e9a8ca32cd3517d51d6e03 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Thu, 24 May 2018 11:06:22 -0500 Subject: Make ledger-binary-path risky --- ledger-exec.el | 1 + 1 file changed, 1 insertion(+) diff --git a/ledger-exec.el b/ledger-exec.el index f83e3cd..b91faab 100644 --- a/ledger-exec.el +++ b/ledger-exec.el @@ -43,6 +43,7 @@ (defcustom ledger-binary-path "ledger" "Path to the ledger executable." :type 'file + :risky t :group 'ledger-exec) (defun ledger-exec-handle-error (ledger-errfile) -- cgit v1.2.3 From 22f92dd2dbfad6ca4bdd5dce09068fe83d7174ce Mon Sep 17 00:00:00 2001 From: Yuri Khan Date: Sat, 4 Aug 2018 14:48:10 +0700 Subject: ledger-read-transaction: Pre-fill year and month but use full date as default Fixes #126. --- ledger-xact.el | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ledger-xact.el b/ledger-xact.el index 6f61bba..8114f94 100644 --- a/ledger-xact.el +++ b/ledger-xact.el @@ -148,12 +148,15 @@ MOMENT is an encoded date" (defun ledger-read-transaction () "Read the text of a transaction, which is at least the current date." - (let ((reference-date (or ledger-add-transaction-last-date (current-time)))) - (read-string - "Transaction: " - ;; Pre-fill year and month, but not day: this assumes DD is the last format arg. - (ledger-format-date reference-date) - 'ledger-minibuffer-history))) + (let* ((reference-date (or ledger-add-transaction-last-date (current-time))) + (full-date-string (ledger-format-date reference-date)) + ;; Pre-fill year and month, but not day: this assumes DD is the last format arg. + (initial-string (replace-regexp-in-string "[0-9]+$" "" full-date-string)) + (entered-string (read-string "Transaction: " + initial-string 'ledger-minibuffer-history))) + (if (string= initial-string entered-string) + full-date-string + entered-string))) (defun ledger-parse-iso-date (date) "Try to parse DATE using `ledger-iso-date-regexp' and return a time value or nil." -- cgit v1.2.3 From a911f9ce30df4fe42174c76e9396c914257ee88e Mon Sep 17 00:00:00 2001 From: Leo Vivier Date: Tue, 28 Aug 2018 11:04:42 +0200 Subject: Add ledger-copy-transaction-insert-blank-line-after Adds a variable to control the insertion of a blank line after a copied transaction. --- ledger-xact.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ledger-xact.el b/ledger-xact.el index 6f61bba..e4358ce 100644 --- a/ledger-xact.el +++ b/ledger-xact.el @@ -120,6 +120,9 @@ MOMENT is an encoded date" mark desc))))) (forward-line)))) +(defvar ledger-copy-transaction-insert-blank-line-after nil + "Non-nil means insert blank line after a transaction inserted with ‘ledger-copy-transaction-at-point’.") + (defun ledger-copy-transaction-at-point (date) "Ask for a new DATE and copy the transaction under point to that date. Leave point on the first amount." (interactive (list @@ -128,7 +131,10 @@ MOMENT is an encoded date" (transaction (buffer-substring-no-properties (car extents) (cadr extents))) (encoded-date (ledger-parse-iso-date date))) (ledger-xact-find-slot encoded-date) - (insert transaction "\n") + (insert transaction + (if (bound-and-true-p ledger-copy-transaction-insert-blank-line-after) + "\n\n" + "\n")) (beginning-of-line -1) (ledger-navigate-beginning-of-xact) (re-search-forward ledger-iso-date-regexp) -- cgit v1.2.3 From 74a87b330870900682380390c8bcb71974128022 Mon Sep 17 00:00:00 2001 From: Leo Vivier Date: Tue, 28 Aug 2018 11:15:10 +0200 Subject: Add info entry for ledger-copy-transaction-insert-blank-line-after --- doc/ledger-mode.texi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi index b4352c8..74f8abb 100644 --- a/doc/ledger-mode.texi +++ b/doc/ledger-mode.texi @@ -328,6 +328,10 @@ An easy way to copy a transaction is to type @kbd{C-c C-k} or menu entry copied transaction, and after having confirmed with @kbd{RET}, new transaction will be inserted at @emph{date} position in buffer. +If you prefer to keep blank lines between your transactions, you can +change the default in +@option{ledger-copy-transaction-insert-blank-line-after}. + @node Editing Amounts, Marking Transactions, Copying Transactions, The Ledger Buffer @section Editing Amounts @kindex C-c C-b -- cgit v1.2.3 From fae0446426bd0727e779b62f9110dfe5f51bc18a Mon Sep 17 00:00:00 2001 From: Leo Vivier Date: Sun, 2 Sep 2018 09:14:55 +0200 Subject: Simplify condition Removes bound-and-true-p from the condition. --- ledger-xact.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger-xact.el b/ledger-xact.el index e4358ce..99222b6 100644 --- a/ledger-xact.el +++ b/ledger-xact.el @@ -132,7 +132,7 @@ MOMENT is an encoded date" (encoded-date (ledger-parse-iso-date date))) (ledger-xact-find-slot encoded-date) (insert transaction - (if (bound-and-true-p ledger-copy-transaction-insert-blank-line-after) + (if ledger-copy-transaction-insert-blank-line-after "\n\n" "\n")) (beginning-of-line -1) -- cgit v1.2.3 From 236b9b24aec7495103fa8ea827a756026f10c455 Mon Sep 17 00:00:00 2001 From: Yuri Khan Date: Sun, 23 Sep 2018 13:19:48 +0700 Subject: ledger-add-transaction: Do not add blank line at end of buffer --- ledger-xact.el | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ledger-xact.el b/ledger-xact.el index 6f61bba..66629e0 100644 --- a/ledger-xact.el +++ b/ledger-xact.el @@ -172,14 +172,17 @@ correct chronological place in the buffer." (let* ((args (with-temp-buffer (insert transaction-text) (eshell-parse-arguments (point-min) (point-max)))) - (ledger-buf (current-buffer))) + (ledger-buf (current-buffer)) + (separator "\n")) (unless insert-at-point (let* ((date (car args)) (parsed-date (ledger-parse-iso-date date))) (setq ledger-add-transaction-last-date parsed-date) (push-mark) ;; TODO: what about when it can't be parsed? - (ledger-xact-find-slot (or parsed-date date)))) + (ledger-xact-find-slot (or parsed-date date)) + (when (looking-at "\n*\\'") + (setq separator "")))) (if (> (length args) 1) (save-excursion (insert @@ -189,9 +192,9 @@ correct chronological place in the buffer." (goto-char (point-min)) (ledger-post-align-postings (point-min) (point-max)) (buffer-string)) - "\n")) + separator)) (progn - (insert (car args) " \n\n") + (insert (car args) " \n" separator) (end-of-line -1))))) (provide 'ledger-xact) -- cgit v1.2.3 From 3ca602d1f66f6175d41e0692e8d45362d58b249b Mon Sep 17 00:00:00 2001 From: Fredrik Salomonsson Date: Sun, 10 Feb 2019 19:36:36 -0800 Subject: Fixed flymake backend error (#155) The `make-process' commands only accepts a list of strings but when `ledger-flymake-be-pedantic' and/or `ledger-flymake-be-explicit' is not set to true it will fail as that list now contains nil. Changed it to just return an empty string when a setting isn't enabled. --- ledger-flymake.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ledger-flymake.el b/ledger-flymake.el index b164832..4492bde 100644 --- a/ledger-flymake.el +++ b/ledger-flymake.el @@ -72,8 +72,8 @@ Flymake calls this with REPORT-FN as needed." :name "ledger-flymake" :noquery t :connection-type 'pipe :buffer (generate-new-buffer " *ledger-flymake*") :command `(,ledger-binary-path "-f" ,file - ,(when ledger-flymake-be-pedantic "--pedantic") - ,(when ledger-flymake-be-explicit "--explicit") + ,(if ledger-flymake-be-pedantic "--pedantic" "") + ,(if ledger-flymake-be-explicit "--explicit" "") "balance") :sentinel (lambda (proc _event) -- cgit v1.2.3 From 253a20dc62e137ed0ed8e1dd8614ecba116610ea Mon Sep 17 00:00:00 2001 From: Fredrik Salomonsson Date: Mon, 11 Feb 2019 13:33:35 -0800 Subject: Cleaner fix for the flymake backend. (#157) Removing the nil entries in the command list instead of setting them to empty strings. As empty strings might mess with the command. --- ledger-flymake.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ledger-flymake.el b/ledger-flymake.el index 4492bde..06bddd7 100644 --- a/ledger-flymake.el +++ b/ledger-flymake.el @@ -71,10 +71,12 @@ Flymake calls this with REPORT-FN as needed." (make-process :name "ledger-flymake" :noquery t :connection-type 'pipe :buffer (generate-new-buffer " *ledger-flymake*") - :command `(,ledger-binary-path "-f" ,file - ,(if ledger-flymake-be-pedantic "--pedantic" "") - ,(if ledger-flymake-be-explicit "--explicit" "") - "balance") + :command (cl-remove + nil + `(,ledger-binary-path "-f" ,file + ,(when ledger-flymake-be-pedantic "--pedantic") + ,(when ledger-flymake-be-explicit "--explicit") + "balance")) :sentinel (lambda (proc _event) ;; Check that the process has indeed exited, as it might -- cgit v1.2.3 From 6e36a0ca9499d65217d5f2263831bdcadefd9115 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Wed, 20 Feb 2019 09:02:22 -0600 Subject: * doc/ledger-mode.texi: Change dircategory to Emacs --- doc/ledger-mode.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi index e47bdae..9249a5e 100644 --- a/doc/ledger-mode.texi +++ b/doc/ledger-mode.texi @@ -47,7 +47,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @end copying -@dircategory Major Modes +@dircategory Emacs @direntry * Ledger Mode: (ledger-mode). Command-Line Accounting @end direntry -- cgit v1.2.3 From 6dc3090128fa34c8ff3bc939b8f06a7798d23d48 Mon Sep 17 00:00:00 2001 From: Philip Rosenberg-Watt Date: Fri, 1 Mar 2019 13:18:25 -0700 Subject: Use --real when reconciling accounts Accounts containing virtual transactions will not show the appropriate cleared balance. This closes #153. --- ledger-reconcile.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger-reconcile.el b/ledger-reconcile.el index fc5779a..4522b21 100644 --- a/ledger-reconcile.el +++ b/ledger-reconcile.el @@ -181,7 +181,7 @@ Possible values are '(date)', '(amount)', '(payee)' or '(0)' for no sorting, i.e ;; split arguments like the shell does, so you need to ;; specify the individual fields in the command line. (ledger-exec-ledger buffer (current-buffer) - "balance" "--limit" "cleared or pending" "--empty" "--collapse" + "balance" "--real" "--limit" "cleared or pending" "--empty" "--collapse" "--format" "%(scrub(display_total))" account) (ledger-split-commodity-string (buffer-substring-no-properties (point-min) (point-max))))) -- cgit v1.2.3 From 2e845fa9fa9931cd3f678aab9eb6d29c9b7a293b Mon Sep 17 00:00:00 2001 From: "Kevin J. Foley" Date: Sun, 17 Mar 2019 10:36:56 -0400 Subject: Respect `ledger-occur-use-face-shown' when using `leger-occur' --- ledger-occur.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ledger-occur.el b/ledger-occur.el index 6741b72..bfd006e 100644 --- a/ledger-occur.el +++ b/ledger-occur.el @@ -106,7 +106,8 @@ currently active." (defun ledger-occur-make-visible-overlay (beg end) (let ((ovl (make-overlay beg end (current-buffer)))) (overlay-put ovl ledger-occur-overlay-property-name t) - (overlay-put ovl 'font-lock-face 'ledger-occur-xact-face))) + (when ledger-occur-use-face-shown + (overlay-put ovl 'font-lock-face 'ledger-occur-xact-face)))) (defun ledger-occur-make-invisible-overlay (beg end) (let ((ovl (make-overlay beg end (current-buffer)))) -- cgit v1.2.3 From 3a350db5456bc419cc7cf1e2338eab6c5a999c84 Mon Sep 17 00:00:00 2001 From: Yuri Khan Date: Sun, 24 Mar 2019 17:05:49 +0700 Subject: ledger-add-transaction: On new transaction, leave point after date --- ledger-xact.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ledger-xact.el b/ledger-xact.el index e4ef50b..76617c3 100644 --- a/ledger-xact.el +++ b/ledger-xact.el @@ -200,8 +200,8 @@ correct chronological place in the buffer." (buffer-string)) separator)) (progn - (insert (car args) " \n" separator) - (end-of-line -1))))) + (insert (car args) " ") + (save-excursion (insert "\n" separator)))))) (provide 'ledger-xact) -- cgit v1.2.3 From 219d52cfbfea563b04e79b2a30fa3098dd933728 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Mon, 25 Mar 2019 18:21:47 -0500 Subject: Make ledger-report work in ledger-report-mode buffers * ledger-report.el (ledger-master-file): Move up to silence compiler warning. (ledger-report-mode-map): Bind C-c C-o C-r to ledger-report. (ledger-report): Set ledger-master-file in ledger-report. --- ledger-report.el | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ledger-report.el b/ledger-report.el index c0adaba..0de4d5d 100644 --- a/ledger-report.el +++ b/ledger-report.el @@ -150,6 +150,9 @@ when running reports?" (defvar ledger-report-is-reversed nil) (defvar ledger-report-cursor-line-number nil) +(defvar-local ledger-master-file nil + "The master file for the current buffer. +See documentation for the function `ledger-master-file'") (defun ledger-report-reverse-report () "Reverse the order of the report." @@ -188,6 +191,7 @@ when running reports?" #'ledger-report-save) (define-key map [(control ?c) (control ?l) (control ?e)] #'ledger-report-edit-report) + (define-key map [(control ?c) (control ?o) (control ?r)] #'ledger-report) (define-key map (kbd "M-p") #'ledger-report-previous-month) (define-key map (kbd "M-n") #'ledger-report-next-month) (define-key map (kbd "$") #'ledger-report-toggle-default-commodity) @@ -265,9 +269,10 @@ used to generate the buffer, navigating the buffer, etc." (let ((rname (ledger-report-read-name)) (edit (not (null current-prefix-arg)))) (list rname edit)))) - (let ((buf (find-file-noselect (ledger-master-file))) - (rbuf (get-buffer ledger-report-buffer-name)) - (wcfg (current-window-configuration))) + (let* ((file (ledger-master-file)) + (buf (find-file-noselect file)) + (rbuf (get-buffer ledger-report-buffer-name)) + (wcfg (current-window-configuration))) (if rbuf (kill-buffer rbuf)) (with-current-buffer @@ -279,6 +284,7 @@ used to generate the buffer, navigating the buffer, etc." (set (make-local-variable 'ledger-original-window-cfg) wcfg) (set (make-local-variable 'ledger-report-is-reversed) nil) (set (make-local-variable 'ledger-report-current-month) nil) + (set 'ledger-master-file file) (ledger-do-report (ledger-report-cmd report-name edit)) (ledger-report-maybe-shrink-window) (set-buffer-modified-p nil) @@ -329,10 +335,6 @@ used to generate the buffer, navigating the buffer, etc." ;; General helper functions -(defvar-local ledger-master-file nil - "The master file for the current buffer. -See documentation for the function `ledger-master-file'") - (defun ledger-master-file () "Return the master file for a ledger file. -- cgit v1.2.3 From f42184ad3d2568883d237da236c134b44a365165 Mon Sep 17 00:00:00 2001 From: Levi Tan Ong Date: Fri, 5 Apr 2019 13:40:54 +0800 Subject: Refactor ledger-xact-payee, add ledger-xact-date --- ledger-xact.el | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/ledger-xact.el b/ledger-xact.el index e4ef50b..14ef927 100644 --- a/ledger-xact.el +++ b/ledger-xact.el @@ -62,16 +62,30 @@ (move-overlay ledger-xact-highlight-overlay b (+ 1 e)) (move-overlay ledger-xact-highlight-overlay 1 1)))))) -(defun ledger-xact-payee () - "Return the payee of the transaction containing point or nil." +(defun ledger-xact-context () + "Return the context of the transaction containing point or nil." (let ((i 0)) (while (eq (ledger-context-line-type (ledger-context-other-line i)) 'acct-transaction) (setq i (- i 1))) (let ((context-info (ledger-context-other-line i))) (if (eq (ledger-context-line-type context-info) 'xact) - (ledger-context-field-value context-info 'payee) + context-info nil)))) +(defun ledger-xact-payee () + "Return the payee of the transaction containing point or nil." + (let ((xact-context (ledger-xact-context))) + (if xact-context + (ledger-context-field-value xact-context 'payee) + nil))) + +(defun ledger-xact-date () + "Return the date of the transaction containing point or nil." + (let ((xact-context (ledger-xact-context))) + (if xact-context + (ledger-context-field-value xact-context 'date) + nil))) + (defun ledger-time-less-p (t1 t2) "Say whether time value T1 is less than time value T2." ;; TODO: assert listp, or support when both are strings -- cgit v1.2.3 From b65c984f761f27c3d30256cea82e03e02a635b8f Mon Sep 17 00:00:00 2001 From: Tim Landscheidt Date: Sun, 7 Apr 2019 16:36:22 +0000 Subject: Clean up temporary files when no longer needed --- ledger-exec.el | 26 ++++++++++++++------------ test/test-helper.el | 3 ++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ledger-exec.el b/ledger-exec.el index f83e3cd..58eca4f 100644 --- a/ledger-exec.el +++ b/ledger-exec.el @@ -75,18 +75,20 @@ otherwise the error output is displayed and an error is raised." (outbuf (or output-buffer (generate-new-buffer " *ledger-tmp*"))) (errfile (make-temp-file "ledger-errors"))) - (with-current-buffer buf - (let ((exit-code - (let ((coding-system-for-write 'utf-8) - (coding-system-for-read 'utf-8)) - (apply #'call-process-region - (append (list (point-min) (point-max) - ledger-binary-path nil (list outbuf errfile) nil "-f" "-") - args))))) - (if (ledger-exec-success-p exit-code outbuf) - outbuf - (display-buffer (ledger-exec-handle-error errfile)) - (error "Ledger execution failed"))))))) + (unwind-protect + (with-current-buffer buf + (let ((exit-code + (let ((coding-system-for-write 'utf-8) + (coding-system-for-read 'utf-8)) + (apply #'call-process-region + (append (list (point-min) (point-max) + ledger-binary-path nil (list outbuf errfile) nil "-f" "-") + args))))) + (if (ledger-exec-success-p exit-code outbuf) + outbuf + (display-buffer (ledger-exec-handle-error errfile)) + (error "Ledger execution failed")))) + (delete-file errfile))))) (defun ledger-version-greater-p (needed) "Verify the ledger binary is usable for `ledger-mode' (version greater than NEEDED)." diff --git a/test/test-helper.el b/test/test-helper.el index f26b4e2..440a5e1 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -126,7 +126,8 @@ always located at the beginning of buffer." (goto-char (point-min)) ,@body) (and ledger-buffer (kill-buffer ledger-buffer)) - (ledger-tests-reset-custom-values 'ledger)))) + (ledger-tests-reset-custom-values 'ledger) + (delete-file temp-file)))) (defun ledger-test-visible-buffer-string () -- cgit v1.2.3 From 20e4b0d13d0338642defcbdf62696e14a4a4e8ff Mon Sep 17 00:00:00 2001 From: Aaron Zeng Date: Tue, 14 May 2019 01:41:12 -0400 Subject: Fix typo in ledger-post-amount-alignment-at docstring (#172) --- ledger-post.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger-post.el b/ledger-post.el index 19b8ae5..8e48d1c 100644 --- a/ledger-post.el +++ b/ledger-post.el @@ -43,7 +43,7 @@ :group 'ledger-post) (defcustom ledger-post-amount-alignment-at :end - "Position at which the amount is ailgned. + "Position at which the amount is aligned. Can be :end to align on the last number of the amount (can be followed by unaligned commodity) or :decimal to align at the -- cgit v1.2.3 From 17a7b6ad1558069fc07f7d6f593a72a9b8346cc6 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Wed, 29 May 2019 10:55:34 +1200 Subject: Fix checkdoc issue in test-helper.el --- test/test-helper.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-helper.el b/test/test-helper.el index 440a5e1..66fb09e 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -167,7 +167,7 @@ The two arguments START and END are character positions." (defun ledger-test-face-groups (fontified) - "Group a fontified string by face. + "Group a FONTIFIED string by face. Return a list of substrings each followed by its face." (cl-loop for start = 0 then end while start -- cgit v1.2.3 From af9ae6037d4696c330e4f96dc3cc41c6e56a87f3 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Tue, 28 May 2019 17:56:29 -0500 Subject: Move from pcomplete to completion-at-point-functions (#174) * Use builtin completion-at-point functions Prefer built-in 'completion-at-point-functions' over pcomplete so that users can use whatever completion engine they prefer. Closes #171 * ledger-complete.el (ledger-complete-at-point): Refactor to return values that 'completion-at-point' can use. (ledger-complete-in-steps): New defcustom to control whether we complete in steps (e.g. "Assets:" then "Assets:Checking") or all in one go (e.g. "Assets:Checking"). * ledger-mode.el (ledger-magic-tab): Remove. (ledger-mode): Add 'ledger-complete-at-point' to 'completion-at-point-functions'. Set tab-always-indent to 'complete, which most closely mimics ledger-mode's previous behavior. Set 'indent-line-function' to 'ledger-indent-line'. * ledger-post.el (ledger-indent-line): New function that controls indentation of the line at point. * Remove all pcomplete code * Fix tests * Don't offer account completion if at beginning of line * Fix ledger-indent-line Without this, if we have a transaction that looks like: 2019-05-28 foo | Assets:Checking $ 1.00 Income:Salary with point at |, pressing TAB generates an error about a cl assertion failing. By deleting horizontal whitespace, we guarantee that we indent the line properly. * Note about how to enable cycling of completions See https://github.com/ledger/ledger-mode/pull/174 --- doc/ledger-mode.texi | 21 ++++++-- ledger-complete.el | 132 +++++++++++++++----------------------------------- ledger-mode.el | 20 +------- ledger-post.el | 12 +++++ test/complete-test.el | 23 ++++----- test/mode-test.el | 26 ++++------ 6 files changed, 91 insertions(+), 143 deletions(-) diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi index 95eae38..06c994d 100644 --- a/doc/ledger-mode.texi +++ b/doc/ledger-mode.texi @@ -273,11 +273,22 @@ current regex. Cancel the narrowing by typing @kbd{C-c C-f} again. @cindex transaction, adding Beyond the two ways of quickly adding transactions (@pxref{Quick Add}) -Ledger-mode assists you by providing robust @kbd{TAB} completion for -payees and accounts. Ledger-mode will scan the existing buffer for -payees and accounts. Included files are not currently included in the -completion scan. Repeatedly hitting @kbd{TAB} will cycle through the -possible completions. +Ledger-mode assists you by providing robust @kbd{TAB} completion for payees and +accounts. Ledger-mode will scan the existing buffer for payees and accounts. +Included files are not currently included in the completion scan. Ledger-mode +respects Emacs's variables that govern @kbd{TAB} completion, see especially +@code{tab-always-indent}. + +To cycle between completions when hitting @kbd{TAB} multiple times, you can +adjust the standard completion configuration like this: + +@lisp +(add-hook 'ledger-mode-hook + (lambda () + (setq-local tab-always-indent t) + (setq-local completion-cycle-threshold t) + (setq-local ledger-complete-in-steps t))) +@end lisp Ledger-mode can also help you keep your amounts aligned. Setting @option{ledger-post-auto-adjust-amounts} to true tells Ledger-mode to diff --git a/ledger-complete.el b/ledger-complete.el index 48199e7..fdbce72 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -22,11 +22,7 @@ ;;; Commentary: ;; Functions providing payee and account auto complete. -(require 'pcomplete) (require 'cl-lib) -(unless (fboundp 'pcomplete-uniquify-list) - ;; TODO: Remove after dropping support for Emacs < 27 - (defalias 'pcomplete-uniquify-list 'pcomplete-uniqify-list)) ;; Emacs 24.3 compatibility (defun ledger-string-greaterp (string1 string2) @@ -47,11 +43,19 @@ This file will then be used as a source for account name completions." :type 'file :group 'ledger) +(defcustom ledger-complete-in-steps nil + "When non-nil, `ledger-complete-at-point' completes account names in steps. +If nil, full account names are offer for completion." + :type 'boolean + :group 'ledger + :package-version '(ledger-mode . "2019-05-27")) + (defun ledger-parse-arguments () "Parse whitespace separated arguments in the current region." - ;; this is more complex than it appears to need, so that it can work - ;; with pcomplete. See pcomplete-parse-arguments-function for - ;; details + ;; FIXME: We don't use pcomplete anymore. + ;; This is more complex than it appears + ;; to need, so that it can work with pcomplete. See + ;; pcomplete-parse-arguments-function for details (let* ((begin (save-match-data (if (looking-back (concat "^\\(" ledger-iso-date-regexp "=\\|\\)" ledger-incomplete-date-regexp) nil) @@ -90,7 +94,7 @@ This file will then be used as a source for account name completions." (setq payees-list (cons (match-string-no-properties 3) payees-list))))) ;; add the payee ;; to the list - (pcomplete-uniquify-list (nreverse payees-list)))) + (delete-dups (sort payees-list #'string-lessp)))) (defun ledger-accounts-deduplicate-sorted (l) "Remove duplicates from a sorted list of strings L." @@ -126,12 +130,12 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." (interactive) (let ((account-tree (list t)) (account-elements nil) - (prefix (or (car pcomplete-args) ""))) + (prefix "")) (save-excursion (goto-char (point-min)) (dolist (account - (cl-remove-if-not (lambda (c) (string-prefix-p prefix c pcomplete-ignore-case)) + (cl-remove-if-not (lambda (c) (string-prefix-p prefix c nil)) (ledger-accounts-list))) (let ((root account-tree)) (setq account-elements @@ -223,37 +227,32 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." (defun ledger-complete-at-point () "Do appropriate completion for the thing at point." - (interactive) - (while (pcomplete-here - (cond - ((looking-back (concat "^" ledger-incomplete-date-regexp) nil) - (ledger-complete-date (match-string 1) (match-string 2))) - ((looking-back (concat "^" ledger-iso-date-regexp "=" - ledger-incomplete-date-regexp) nil) - (ledger-complete-effective-date - (match-string 2) (match-string 3) (match-string 4) - (match-string 5) (match-string 6))) - ((eq (save-excursion - (ledger-thing-at-point)) 'transaction) - (if (null current-prefix-arg) - (delete - (caar (ledger-parse-arguments)) - (ledger-payees-in-buffer)) ;; this completes against payee names - (progn - (let ((text (buffer-substring-no-properties - (line-beginning-position) - (line-end-position)))) - (delete-region (line-beginning-position) - (line-end-position)) - (condition-case nil - (ledger-add-transaction text t) - (error nil))) - (forward-line) - (goto-char (line-end-position)) - (search-backward ";" (line-beginning-position) t) - (skip-chars-backward " \t0123456789.,") - (throw 'pcompleted t)))) - (t (ledger-accounts-tree)))))) + (let ((end (point)) + start collection) + (cond (;; Date + (looking-back (concat "^" ledger-incomplete-date-regexp) (line-beginning-position)) + (progn (setq start (match-beginning 0)) + (setq collection (ledger-complete-date (match-string 1) (match-string 2))))) + (;; Effective dates + (looking-back (concat "^" ledger-iso-date-regexp "=" ledger-incomplete-date-regexp) + (line-beginning-position)) + (progn (setq start (line-beginning-position)) + (setq collection (ledger-complete-effective-date + (match-string 2) (match-string 3) (match-string 4) + (match-string 5) (match-string 6))))) + (;; Payees + (eq (save-excursion (ledger-thing-at-point)) 'transaction) + (progn (setq start (save-excursion (backward-word) (point))) + (setq collection #'ledger-payees-in-buffer))) + ((not (bolp)) ;; Accounts + (progn (setq start (save-excursion (back-to-indentation) (point))) + (if ledger-complete-in-steps + (setq collection #'ledger-accounts-tree) + (setq collection #'ledger-accounts-list-in-buffer))))) + (when collection + (list start end (if (functionp collection) + (completion-table-dynamic (lambda (_) (funcall collection))) + collection))))) (defun ledger-trim-trailing-whitespace (str) (replace-regexp-in-string "[ \t]*$" "" str)) @@ -294,57 +293,6 @@ Does not use ledger xact" (if (re-search-backward "\\(\t\\| [ \t]\\)" nil t) (goto-char (match-end 0)))))) - -(defcustom ledger-complete-ignore-case t - "Non-nil means that ledger-complete-at-point will be case-insensitive" - :type 'boolean - :group 'ledger) - -(defun ledger-pcomplete (&optional interactively) - "Complete rip-off of pcomplete from pcomplete.el, only added -ledger-magic-tab in the previous commands list so that -ledger-magic-tab would cycle properly" - (interactive "p") - (let ((pcomplete-ignore-case ledger-complete-ignore-case)) - (if (and interactively - pcomplete-cycle-completions - pcomplete-current-completions - (memq last-command '(ledger-magic-tab - ledger-pcomplete - pcomplete-expand-and-complete - pcomplete-reverse))) - (progn - (delete-char (* -1 pcomplete-last-completion-length)) - (if (eq this-command 'pcomplete-reverse) - (progn - (push (car (last pcomplete-current-completions)) - pcomplete-current-completions) - (setcdr (last pcomplete-current-completions 2) nil)) - (nconc pcomplete-current-completions - (list (car pcomplete-current-completions))) - (setq pcomplete-current-completions - (cdr pcomplete-current-completions))) - (pcomplete-insert-entry pcomplete-last-completion-stub - (car pcomplete-current-completions) - nil pcomplete-last-completion-raw)) - (setq pcomplete-current-completions nil - pcomplete-last-completion-raw nil) - (catch 'pcompleted - (let* (pcomplete-stub - pcomplete-seen pcomplete-norm-func - pcomplete-args pcomplete-last pcomplete-index - pcomplete-autolist - (completions (pcomplete-completions)) - (result (pcomplete-do-complete pcomplete-stub completions)) - (pcomplete-termination-string "")) - (and result - (not (eq (car result) 'listed)) - (cdr result) - (pcomplete-insert-entry pcomplete-stub (cdr result) - (memq (car result) - '(sole shortest)) - pcomplete-last-completion-raw))))))) - (provide 'ledger-complete) ;;; ledger-complete.el ends here diff --git a/ledger-mode.el b/ledger-mode.el index dc92f73..bdd1b5e 100644 --- a/ledger-mode.el +++ b/ledger-mode.el @@ -149,17 +149,6 @@ And calculate the target-delta of the account being reconciled." (when balance (message balance)))) -(defun ledger-magic-tab (&optional interactively) - "Decide what to with with , INTERACTIVELY. -Can indent, complete or align depending on context." - (interactive "p") - (if (= (point) (line-beginning-position)) - (indent-to ledger-post-account-alignment-column) - (if (and (> (point) 1) - (looking-back "\\([^ \t]\\)" 1)) - (ledger-pcomplete interactively) - (ledger-post-align-postings (line-beginning-position) (line-end-position))))) - (defvar ledger-mode-abbrev-table) (defvar ledger-date-string-today (ledger-format-date)) @@ -264,9 +253,7 @@ With a prefix argument, remove the effective date." (define-key map [(control ?c) (control ?l)] #'ledger-display-ledger-stats) (define-key map [(control ?c) (control ?q)] #'ledger-post-align-xact) - (define-key map [tab] #'ledger-magic-tab) (define-key map [(control tab)] #'ledger-post-align-xact) - (define-key map [(control ?i)] #'ledger-magic-tab) (define-key map [(control ?c) tab] #'ledger-fully-complete-xact) (define-key map [(control ?c) (control ?i)] #'ledger-fully-complete-xact) @@ -330,17 +317,14 @@ With a prefix argument, remove the effective date." (setq font-lock-defaults '(ledger-font-lock-keywords t nil nil nil)) (add-hook 'font-lock-extend-region-functions 'ledger-fontify-extend-region) - - (setq-local pcomplete-parse-arguments-function 'ledger-parse-arguments) - (setq-local pcomplete-command-completion-function 'ledger-complete-at-point) - (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t) + (add-hook 'completion-at-point-functions #'ledger-complete-at-point nil t) (add-hook 'after-save-hook 'ledger-report-redo nil t) (add-hook 'post-command-hook 'ledger-highlight-xact-under-point nil t) (ledger-init-load-init-file) (setq-local comment-start ";") - + (setq-local indent-line-function #'ledger-indent-line) (setq-local indent-region-function 'ledger-post-align-postings)) ;;;###autoload diff --git a/ledger-post.el b/ledger-post.el index 8e48d1c..c9de5ba 100644 --- a/ledger-post.el +++ b/ledger-post.el @@ -120,6 +120,18 @@ Looks only as far as END, if supplied, otherwise `point-max'." (delete-char amt-adjust))))))) (forward-line 1)))))) +(defun ledger-indent-line () + "Indent the current line." + (if (save-excursion + (forward-line -1) + (beginning-of-line) + (not (looking-at-p (rx bol (0+ (or "\n" whitespace)) eol)))) + (progn (when (not (= ledger-post-account-alignment-column + (current-indentation))) + (delete-horizontal-space)) + (indent-to ledger-post-account-alignment-column)) + (ledger-post-align-postings (line-beginning-position) (line-end-position)))) + (defun ledger-post-align-dwim () "Align all the posting of the current xact or the current region. diff --git a/test/complete-test.el b/test/complete-test.el index a8028be..a215549 100644 --- a/test/complete-test.el +++ b/test/complete-test.el @@ -35,25 +35,26 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=969 http://bugs.ledger-cli.org/show_bug.cgi?id=582" :tags '(complete regress) - (ledger-tests-with-temp-file - "2013/05/19 Retrait + (let ((ledger-complete-in-steps t)) + (ledger-tests-with-temp-file + "2013/05/19 Retrait Dépense:Alimentation:Épicerie 35 € ; Marché Dépense:Alimentation:Épicerie 8,1 € ; Arum café Dépense:Liquide * Passif:Crédit:BanqueAccord -60,00 €" - (forward-line 1) - (move-end-of-line 1) - (newline) - (insert " Dé") - (call-interactively #'ledger-magic-tab) - (should - (equal (buffer-string) - "2013/05/19 Retrait + (forward-line 1) + (move-end-of-line 1) + (newline) + (insert " Dé") + (call-interactively #'completion-at-point) + (should + (equal (buffer-string) + "2013/05/19 Retrait Dépense:Alimentation:Épicerie 35 € ; Marché Dépense: Dépense:Alimentation:Épicerie 8,1 € ; Arum café Dépense:Liquide - * Passif:Crédit:BanqueAccord -60,00 €")))) + * Passif:Crédit:BanqueAccord -60,00 €"))))) (ert-deftest ledger-complete/test-002 () diff --git a/test/mode-test.el b/test/mode-test.el index 1bfefdd..0135243 100644 --- a/test/mode-test.el +++ b/test/mode-test.el @@ -61,27 +61,19 @@ "Regress test for Bug 256 http://bugs.ledger-cli.org/show_bug.cgi?id=256" :tags '(mode regress) - - (ledger-tests-with-temp-file - "" - - (comment-dwim nil) - (should (equal (buffer-string) "; ")) ; Expected: no space before ';' - )) - + (ledger-tests-with-temp-file "" + (comment-dwim nil) + (should (string-match (rx buffer-start ";" (0+ whitespace)) + ;; Expected: no space before ';' + (buffer-string))))) (ert-deftest ledger-mode/test-003 () "Baseline test for comment-start" :tags '(mode baseline) - - (ledger-tests-with-temp-file - "" - - (setq comment-start "#") - (comment-dwim nil) - (should (equal (buffer-string) "# ")) - )) - + (ledger-tests-with-temp-file "" + (setq comment-start "#") + (comment-dwim nil) + (should (string-match (rx buffer-start "#" (0+ whitespace)) (buffer-string))))) (provide 'mode-test) -- cgit v1.2.3 From e33c12e0503d8352325411d81400d883548103a8 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Wed, 29 May 2019 11:17:34 +1200 Subject: Sort list after deleting duplicates --- ledger-complete.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger-complete.el b/ledger-complete.el index fdbce72..e6999c3 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -94,7 +94,7 @@ If nil, full account names are offer for completion." (setq payees-list (cons (match-string-no-properties 3) payees-list))))) ;; add the payee ;; to the list - (delete-dups (sort payees-list #'string-lessp)))) + (sort (delete-dups payees-list) #'string-lessp))) (defun ledger-accounts-deduplicate-sorted (l) "Remove duplicates from a sorted list of strings L." -- cgit v1.2.3 From 07ba7b2d0f7401cce2037423dfaa54f25bbf2d4e Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Wed, 29 May 2019 11:18:16 +1200 Subject: Remove redundant optional nil argument --- ledger-complete.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger-complete.el b/ledger-complete.el index e6999c3..0a6b431 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -135,7 +135,7 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." (goto-char (point-min)) (dolist (account - (cl-remove-if-not (lambda (c) (string-prefix-p prefix c nil)) + (cl-remove-if-not (lambda (c) (string-prefix-p prefix c)) (ledger-accounts-list))) (let ((root account-tree)) (setq account-elements -- cgit v1.2.3 From 01935aedf384897d633061ccdedbb78abf402cf2 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Wed, 29 May 2019 11:20:29 +1200 Subject: Remove redundant progn --- ledger-complete.el | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ledger-complete.el b/ledger-complete.el index 0a6b431..bc7bb4d 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -231,24 +231,24 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." start collection) (cond (;; Date (looking-back (concat "^" ledger-incomplete-date-regexp) (line-beginning-position)) - (progn (setq start (match-beginning 0)) - (setq collection (ledger-complete-date (match-string 1) (match-string 2))))) + (setq start (match-beginning 0)) + (setq collection (ledger-complete-date (match-string 1) (match-string 2)))) (;; Effective dates (looking-back (concat "^" ledger-iso-date-regexp "=" ledger-incomplete-date-regexp) (line-beginning-position)) - (progn (setq start (line-beginning-position)) - (setq collection (ledger-complete-effective-date - (match-string 2) (match-string 3) (match-string 4) - (match-string 5) (match-string 6))))) + (setq start (line-beginning-position)) + (setq collection (ledger-complete-effective-date + (match-string 2) (match-string 3) (match-string 4) + (match-string 5) (match-string 6)))) (;; Payees (eq (save-excursion (ledger-thing-at-point)) 'transaction) - (progn (setq start (save-excursion (backward-word) (point))) - (setq collection #'ledger-payees-in-buffer))) + (setq start (save-excursion (backward-word) (point))) + (setq collection #'ledger-payees-in-buffer)) ((not (bolp)) ;; Accounts - (progn (setq start (save-excursion (back-to-indentation) (point))) - (if ledger-complete-in-steps - (setq collection #'ledger-accounts-tree) - (setq collection #'ledger-accounts-list-in-buffer))))) + (setq start (save-excursion (back-to-indentation) (point))) + (setq collection (if ledger-complete-in-steps + #'ledger-accounts-tree + #'ledger-accounts-list-in-buffer)))) (when collection (list start end (if (functionp collection) (completion-table-dynamic (lambda (_) (funcall collection))) -- cgit v1.2.3 From 48677be8ededb5713ef5a6f2aa6a7df6e7ef519d Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Wed, 29 May 2019 11:21:29 +1200 Subject: Remove redundant call to beginning-of-line --- ledger-post.el | 1 - 1 file changed, 1 deletion(-) diff --git a/ledger-post.el b/ledger-post.el index c9de5ba..ad2b893 100644 --- a/ledger-post.el +++ b/ledger-post.el @@ -124,7 +124,6 @@ Looks only as far as END, if supplied, otherwise `point-max'." "Indent the current line." (if (save-excursion (forward-line -1) - (beginning-of-line) (not (looking-at-p (rx bol (0+ (or "\n" whitespace)) eol)))) (progn (when (not (= ledger-post-account-alignment-column (current-indentation))) -- cgit v1.2.3 From 5646e5b858f2357b32fe2dbf8e00c82307d905a6 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Wed, 29 May 2019 11:22:50 +1200 Subject: Reverse condition to avoid progn in "if" --- ledger-post.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ledger-post.el b/ledger-post.el index ad2b893..a274e18 100644 --- a/ledger-post.el +++ b/ledger-post.el @@ -124,12 +124,12 @@ Looks only as far as END, if supplied, otherwise `point-max'." "Indent the current line." (if (save-excursion (forward-line -1) - (not (looking-at-p (rx bol (0+ (or "\n" whitespace)) eol)))) - (progn (when (not (= ledger-post-account-alignment-column - (current-indentation))) - (delete-horizontal-space)) - (indent-to ledger-post-account-alignment-column)) - (ledger-post-align-postings (line-beginning-position) (line-end-position)))) + (looking-at-p (rx bol (0+ (or "\n" whitespace)) eol))) + (ledger-post-align-postings (line-beginning-position) (line-end-position)) + (when (not (= ledger-post-account-alignment-column + (current-indentation))) + (delete-horizontal-space)) + (indent-to ledger-post-account-alignment-column))) (defun ledger-post-align-dwim () "Align all the posting of the current xact or the current region. -- cgit v1.2.3 From 469c6e08542d204c10123b21b4a2435a8fb3066a Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Wed, 29 May 2019 11:23:25 +1200 Subject: Prefer "unless" to "when" + "not" --- ledger-post.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ledger-post.el b/ledger-post.el index a274e18..5dc9ff1 100644 --- a/ledger-post.el +++ b/ledger-post.el @@ -126,8 +126,7 @@ Looks only as far as END, if supplied, otherwise `point-max'." (forward-line -1) (looking-at-p (rx bol (0+ (or "\n" whitespace)) eol))) (ledger-post-align-postings (line-beginning-position) (line-end-position)) - (when (not (= ledger-post-account-alignment-column - (current-indentation))) + (unless (= ledger-post-account-alignment-column (current-indentation)) (delete-horizontal-space)) (indent-to ledger-post-account-alignment-column))) -- cgit v1.2.3 From 5255c07452f35593a70916930079676363cacb33 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Wed, 29 May 2019 11:24:57 +1200 Subject: Fix docstring in typo --- ledger-complete.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger-complete.el b/ledger-complete.el index bc7bb4d..03112f2 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -45,7 +45,7 @@ This file will then be used as a source for account name completions." (defcustom ledger-complete-in-steps nil "When non-nil, `ledger-complete-at-point' completes account names in steps. -If nil, full account names are offer for completion." +If nil, full account names are offered for completion." :type 'boolean :group 'ledger :package-version '(ledger-mode . "2019-05-27")) -- cgit v1.2.3 From 2a5044d00836e7e5d5b43cc02b300c6286b3e953 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Wed, 29 May 2019 17:12:13 -0500 Subject: Minor cleanup after moving completion systems (#175) * doc/ledger-mode.texi (Adding Transactions): the example for tab completion should set 'tab-always-indent' to 'complete, not t. * ledger-complete.el (ledger-complete-at-point): Use `ledger-accounts-list', which respects 'ledger-accounts-file' --- doc/ledger-mode.texi | 2 +- ledger-complete.el | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi index 06c994d..1930680 100644 --- a/doc/ledger-mode.texi +++ b/doc/ledger-mode.texi @@ -285,7 +285,7 @@ adjust the standard completion configuration like this: @lisp (add-hook 'ledger-mode-hook (lambda () - (setq-local tab-always-indent t) + (setq-local tab-always-indent 'complete) (setq-local completion-cycle-threshold t) (setq-local ledger-complete-in-steps t))) @end lisp diff --git a/ledger-complete.el b/ledger-complete.el index 03112f2..26b8c69 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -248,7 +248,7 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." (setq start (save-excursion (back-to-indentation) (point))) (setq collection (if ledger-complete-in-steps #'ledger-accounts-tree - #'ledger-accounts-list-in-buffer)))) + #'ledger-accounts-list)))) (when collection (list start end (if (functionp collection) (completion-table-dynamic (lambda (_) (funcall collection))) -- cgit v1.2.3 From 2c0c68afc487b68a2fbaed2ece82363155d2ede5 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Wed, 5 Jun 2019 16:03:57 +1200 Subject: Complete accounts better, and realign postings afterwards --- ledger-complete.el | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/ledger-complete.el b/ledger-complete.el index 26b8c69..04ced58 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -228,7 +228,8 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." (defun ledger-complete-at-point () "Do appropriate completion for the thing at point." (let ((end (point)) - start collection) + start collection + realign-after) (cond (;; Date (looking-back (concat "^" ledger-incomplete-date-regexp) (line-beginning-position)) (setq start (match-beginning 0)) @@ -244,15 +245,24 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." (eq (save-excursion (ledger-thing-at-point)) 'transaction) (setq start (save-excursion (backward-word) (point))) (setq collection #'ledger-payees-in-buffer)) - ((not (bolp)) ;; Accounts - (setq start (save-excursion (back-to-indentation) (point))) - (setq collection (if ledger-complete-in-steps + ((looking-back (rx-to-string `(seq bol (repeat ,ledger-post-account-alignment-column ?\ ) (group (zero-or-more (not space))))) (line-beginning-position)) + (setq start (match-beginning 1) + end (save-excursion + (search-forward-regexp (rx (zero-or-more (not space)))) + (point)) + realign-after t + collection (if ledger-complete-in-steps #'ledger-accounts-tree #'ledger-accounts-list)))) (when collection - (list start end (if (functionp collection) - (completion-table-dynamic (lambda (_) (funcall collection))) - collection))))) + (list start end + (if (functionp collection) + (completion-table-dynamic (lambda (_) (funcall collection))) + collection) + :exit-function (if realign-after + (lambda (&rest _) + (ledger-post-align-postings (line-beginning-position) (line-end-position))) + 'ignore))))) (defun ledger-trim-trailing-whitespace (str) (replace-regexp-in-string "[ \t]*$" "" str)) -- cgit v1.2.3 From e9597757e4a9d79bde17f5c76c68867b274edd26 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Wed, 5 Jun 2019 16:07:35 +1200 Subject: When testing, handle EMACS paths containing spaces --- test/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Makefile b/test/Makefile index 6d15ff0..7d54410 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,7 +1,7 @@ EMACS ?= emacs EMACS_FLAGS = --quick --directory . --directory .. -EMACS_BATCH = $(EMACS) --batch $(EMACS_FLAGS) -EMACS_INTERACTIVE = $(EMACS) $(EMACS_FLAGS) +EMACS_BATCH = "$(EMACS)" --batch $(EMACS_FLAGS) +EMACS_INTERACTIVE = "$(EMACS)" $(EMACS_FLAGS) EL := $(wildcard *.el) ELC := $(patsubst %.el,%.elc,$(EL)) -- cgit v1.2.3 From fe15ccee1048652084375162e1300954d19d9575 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Thu, 6 Jun 2019 09:30:05 +1200 Subject: Remove docs for long-defunct ledger-post-auto-adjust-amounts option See #174 --- doc/ledger-mode.texi | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi index 1930680..ae7b0c6 100644 --- a/doc/ledger-mode.texi +++ b/doc/ledger-mode.texi @@ -267,7 +267,6 @@ current regex. Cancel the narrowing by typing @kbd{C-c C-f} again. @node Adding Transactions, Copying Transactions, The Ledger Buffer, The Ledger Buffer @section Adding Transactions -@findex ledger-post-auto-adjust-amounts @findex ledger-post-amount-alignment-column @kindex TAB @cindex transaction, adding @@ -290,11 +289,11 @@ adjust the standard completion configuration like this: (setq-local ledger-complete-in-steps t))) @end lisp -Ledger-mode can also help you keep your amounts aligned. Setting -@option{ledger-post-auto-adjust-amounts} to true tells Ledger-mode to -automatically place any amounts such that their last digit is aligned to -the column specified by @option{ledger-post-amount-alignment-column}, -which defaults to @samp{52}. @xref{Ledger Post Customization Group}. +Ledger-mode will help you keep your amounts aligned. When indenting or +completing, Ledger-mode will automatically place any amounts such that their +last digit is aligned to the column specified by +@option{ledger-post-amount-alignment-column}, which defaults to +@samp{52}. @xref{Ledger Post Customization Group}. @menu * Setting a Transactions Effective Date:: @@ -1128,10 +1127,6 @@ Ledger Post: @ftable @option -@item ledger-post-auto-adjust-amounts -If non-nil, then automatically align amounts to column specified in -@option{ledger-post-amount-alignment-column}. - @item ledger-post-amount-alignment-column The column Ledger-mode uses to align amounts. -- cgit v1.2.3 From c29a5021229045737de0ce7d56080194eb9bb15c Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Thu, 6 Jun 2019 10:35:00 +1200 Subject: Fix completion of account names when at end of line --- ledger-complete.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger-complete.el b/ledger-complete.el index 04ced58..0075f17 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -248,7 +248,7 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." ((looking-back (rx-to-string `(seq bol (repeat ,ledger-post-account-alignment-column ?\ ) (group (zero-or-more (not space))))) (line-beginning-position)) (setq start (match-beginning 1) end (save-excursion - (search-forward-regexp (rx (zero-or-more (not space)))) + (search-forward-regexp (rx (zero-or-more (not space))) (line-end-position)) (point)) realign-after t collection (if ledger-complete-in-steps -- cgit v1.2.3 From 3fe6662d562c70e8440ba108b18b95b0e84928be Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Thu, 6 Jun 2019 10:35:42 +1200 Subject: Make ledger-indent-line more robust --- ledger-post.el | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ledger-post.el b/ledger-post.el index 5dc9ff1..71665e7 100644 --- a/ledger-post.el +++ b/ledger-post.el @@ -122,13 +122,17 @@ Looks only as far as END, if supplied, otherwise `point-max'." (defun ledger-indent-line () "Indent the current line." - (if (save-excursion - (forward-line -1) - (looking-at-p (rx bol (0+ (or "\n" whitespace)) eol))) - (ledger-post-align-postings (line-beginning-position) (line-end-position)) - (unless (= ledger-post-account-alignment-column (current-indentation)) - (delete-horizontal-space)) - (indent-to ledger-post-account-alignment-column))) + ;; Ensure indent if the previous line was indented + (let ((indent-level (save-excursion (if (or (eq 'posting (ledger-thing-at-point)) + (progn (forward-line -1) + (> (current-indentation) 0))) + ledger-post-account-alignment-column + 0)))) + (unless (= (current-indentation) indent-level) + (back-to-indentation) + (delete-horizontal-space t) + (indent-to indent-level))) + (ledger-post-align-postings (line-beginning-position) (line-end-position))) (defun ledger-post-align-dwim () "Align all the posting of the current xact or the current region. -- cgit v1.2.3 From f74fb095d7d956b66a8d844ec11db753c7a57c7d Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 7 Jun 2019 08:13:32 +1200 Subject: Allow reports to be triggered from txns with effective dates This is an alternate formulation of #121 --- ledger-context.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger-context.el b/ledger-context.el index ac76708..5a214d7 100644 --- a/ledger-context.el +++ b/ledger-context.el @@ -39,7 +39,7 @@ (defconst ledger-balance-assertion-string ledger-balance-assertion-regexp) (defconst ledger-comment-string "[ \t]*;[ \t]*\\(.*?\\)") (defconst ledger-nil-string "\\([ \t]+\\)") -(defconst ledger-date-string "^\\([0-9]\\{4\\}[/-][01]?[0-9][/-][0123]?[0-9]\\)") +(defconst ledger-date-string (concat "^" ledger-full-date-regexp)) (defconst ledger-code-string "\\((.*)\\)?") (defconst ledger-payee-string "\\(.*[^[:space:]]\\)") -- cgit v1.2.3 From 86f36d9776489cec14b404d57479c3f7bf65f1af Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 7 Jun 2019 08:18:43 +1200 Subject: When completing accounts, don't assume spaces over tabs --- ledger-complete.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger-complete.el b/ledger-complete.el index 0075f17..2f44bed 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -245,7 +245,7 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." (eq (save-excursion (ledger-thing-at-point)) 'transaction) (setq start (save-excursion (backward-word) (point))) (setq collection #'ledger-payees-in-buffer)) - ((looking-back (rx-to-string `(seq bol (repeat ,ledger-post-account-alignment-column ?\ ) (group (zero-or-more (not space))))) (line-beginning-position)) + ((looking-back (rx-to-string `(seq bol (one-or-more space) (group (zero-or-more (not space))))) (line-beginning-position)) (setq start (match-beginning 1) end (save-excursion (search-forward-regexp (rx (zero-or-more (not space))) (line-end-position)) -- cgit v1.2.3 From dfd6d0efdb6e6c9dca2f5d2ccd924b3f361120bd Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 7 Jun 2019 09:50:59 +1200 Subject: Fix indentation on first posting line --- ledger-post.el | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ledger-post.el b/ledger-post.el index 71665e7..c55b2fa 100644 --- a/ledger-post.el +++ b/ledger-post.el @@ -123,9 +123,8 @@ Looks only as far as END, if supplied, otherwise `point-max'." (defun ledger-indent-line () "Indent the current line." ;; Ensure indent if the previous line was indented - (let ((indent-level (save-excursion (if (or (eq 'posting (ledger-thing-at-point)) - (progn (forward-line -1) - (> (current-indentation) 0))) + (let ((indent-level (save-excursion (if (progn (forward-line -1) + (memq (ledger-thing-at-point) '(transaction posting))) ledger-post-account-alignment-column 0)))) (unless (= (current-indentation) indent-level) -- cgit v1.2.3 From 54fb9cd6e9785f4f36e222ed4be902454b6f7980 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Sat, 8 Jun 2019 15:40:50 +1200 Subject: When completing from half-way through a symbol, kill the suffix when done --- ledger-complete.el | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ledger-complete.el b/ledger-complete.el index 2f44bed..09d41c1 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -229,11 +229,15 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." "Do appropriate completion for the thing at point." (let ((end (point)) start collection - realign-after) + realign-after + delete-suffix) (cond (;; Date (looking-back (concat "^" ledger-incomplete-date-regexp) (line-beginning-position)) - (setq start (match-beginning 0)) - (setq collection (ledger-complete-date (match-string 1) (match-string 2)))) + (setq collection (ledger-complete-date (match-string 1) (match-string 2)) + start (match-beginning 0) + delete-suffix (save-match-data + (when (looking-at (rx (one-or-more (or digit (any ?/ ?-))))) + (length (match-string 0)))))) (;; Effective dates (looking-back (concat "^" ledger-iso-date-regexp "=" ledger-incomplete-date-regexp) (line-beginning-position)) @@ -247,9 +251,9 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." (setq collection #'ledger-payees-in-buffer)) ((looking-back (rx-to-string `(seq bol (one-or-more space) (group (zero-or-more (not space))))) (line-beginning-position)) (setq start (match-beginning 1) - end (save-excursion - (search-forward-regexp (rx (zero-or-more (not space))) (line-end-position)) - (point)) + delete-suffix (save-excursion + (when (search-forward-regexp (rx (or eol (repeat 2 space))) (line-end-position) t) + (- (match-beginning 0) end))) realign-after t collection (if ledger-complete-in-steps #'ledger-accounts-tree @@ -259,10 +263,12 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." (if (functionp collection) (completion-table-dynamic (lambda (_) (funcall collection))) collection) - :exit-function (if realign-after - (lambda (&rest _) - (ledger-post-align-postings (line-beginning-position) (line-end-position))) - 'ignore))))) + :exit-function (lambda (&rest _) + (when delete-suffix + (delete-char delete-suffix)) + (when realign-after + (ledger-post-align-postings (line-beginning-position) (line-end-position)))) + 'ignore)))) (defun ledger-trim-trailing-whitespace (str) (replace-regexp-in-string "[ \t]*$" "" str)) -- cgit v1.2.3 From 03c3d01379d3c88834ecabdd3d818cfc7f0ca38f Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Sat, 15 Jun 2019 14:49:02 +1200 Subject: Don't fail to calculate indentation if transaction is on first line This caused a hang with electric-indent-mode --- ledger-post.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ledger-post.el b/ledger-post.el index c55b2fa..b3ec9b1 100644 --- a/ledger-post.el +++ b/ledger-post.el @@ -123,8 +123,8 @@ Looks only as far as END, if supplied, otherwise `point-max'." (defun ledger-indent-line () "Indent the current line." ;; Ensure indent if the previous line was indented - (let ((indent-level (save-excursion (if (progn (forward-line -1) - (memq (ledger-thing-at-point) '(transaction posting))) + (let ((indent-level (save-excursion (if (progn (when (zerop (forward-line -1)) + (memq (ledger-thing-at-point) '(transaction posting)))) ledger-post-account-alignment-column 0)))) (unless (= (current-indentation) indent-level) -- cgit v1.2.3 From c5cc2f7b26237e828b1083751e3f4a38d332549a Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Sat, 15 Jun 2019 15:03:14 +1200 Subject: Allow automatic realignment of posting amounts to be disabled Fixes #176 --- doc/ledger-mode.texi | 3 +++ ledger-complete.el | 2 +- ledger-post.el | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi index ae7b0c6..555b005 100644 --- a/doc/ledger-mode.texi +++ b/doc/ledger-mode.texi @@ -295,6 +295,9 @@ last digit is aligned to the column specified by @option{ledger-post-amount-alignment-column}, which defaults to @samp{52}. @xref{Ledger Post Customization Group}. +To prevent the automatic realignment of amounts, disable +@option{ledger-post-auto-align}. @xref{Ledger Post Customization Group}. + @menu * Setting a Transactions Effective Date:: * Quick Balance Display:: diff --git a/ledger-complete.el b/ledger-complete.el index 09d41c1..e030fbe 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -266,7 +266,7 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." :exit-function (lambda (&rest _) (when delete-suffix (delete-char delete-suffix)) - (when realign-after + (when (and realign-after ledger-post-auto-align) (ledger-post-align-postings (line-beginning-position) (line-end-position)))) 'ignore)))) diff --git a/ledger-post.el b/ledger-post.el index b3ec9b1..982863d 100644 --- a/ledger-post.el +++ b/ledger-post.el @@ -52,6 +52,12 @@ decimal separator." (const :tag "align at the decimal separator" :decimal)) :group 'ledger-post) +(defcustom ledger-post-auto-align t + "When non-nil, realign post amounts when indenting or completing." + :type 'boolean + :group 'ledger-post + :safe 'booleanp) + (defun ledger-next-amount (&optional end) "Move point to the next amount, as long as it is not past END. Return the width of the amount field as an integer and leave @@ -131,7 +137,8 @@ Looks only as far as END, if supplied, otherwise `point-max'." (back-to-indentation) (delete-horizontal-space t) (indent-to indent-level))) - (ledger-post-align-postings (line-beginning-position) (line-end-position))) + (when ledger-post-auto-align + (ledger-post-align-postings (line-beginning-position) (line-end-position)))) (defun ledger-post-align-dwim () "Align all the posting of the current xact or the current region. -- cgit v1.2.3 From 9b3b97303b196013eb3da65380184b60c130f246 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Mon, 17 Jun 2019 11:49:52 +1200 Subject: ledger-navigate: Don't assume forward-line moves point This fixes #144 --- ledger-navigate.el | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/ledger-navigate.el b/ledger-navigate.el index eb5765c..a96f4b5 100644 --- a/ledger-navigate.el +++ b/ledger-navigate.el @@ -97,37 +97,42 @@ Requires empty line separating xacts." (list (ledger-navigate-beginning-of-xact) (ledger-navigate-end-of-xact)))) +(defun ledger-navigate-skip-lines-backwards (re) + "Move backwards if necessary until RE does not match at the beginning of the line." + (beginning-of-line) + (while (and (looking-at-p re) + (zerop (forward-line -1))))) + +(defun ledger-navigate-skip-lines-forwards (re) + "Move forwards if necessary until RE does not match at the beginning of the line." + (beginning-of-line) + (while (and (looking-at-p re) + (zerop (forward-line 1))))) + (defun ledger-navigate-find-directive-extents (pos) "Return the extents of the directive at POS." (goto-char pos) - (let ((begin (progn (beginning-of-line) - (while (looking-at "[ \t]\\|end[[:blank:]]+\\(?:comment\\|test\\)") - (forward-line -1)) + (let ((begin (progn (ledger-navigate-skip-lines-backwards "[ \t]\\|end[[:blank:]]+\\(?:comment\\|test\\)") (point))) (end (progn (forward-line 1) - (while (looking-at "[ \t]") - (forward-line 1)) - (point)))) + (ledger-navigate-skip-lines-forwards "[ \t]") + (point))) + (comment-re " *;")) ;; handle block comments here (goto-char begin) (cond - ((looking-at " *;") + ((looking-at comment-re) (progn - (while (and (looking-at " *;") - (> (point) (point-min))) - (forward-line -1)) + (ledger-navigate-skip-lines-backwards comment-re) ;; We are either at the beginning of the buffer, or we found ;; a line outside the comment, or both. If we are outside ;; the comment then we need to move forward a line. - (unless (looking-at " *;") + (unless (looking-at comment-re) (forward-line 1) (beginning-of-line)) (setq begin (point)) (goto-char pos) - (beginning-of-line) - (while (and (looking-at " *;") - (< (point) (point-max))) - (forward-line 1)) + (ledger-navigate-skip-lines-forwards comment-re) (setq end (point)))) ((looking-at "\\(?:comment\\|test\\)\\>") (setq end (or (save-match-data @@ -142,20 +147,17 @@ Requires empty line separating xacts." (let ((begin (progn (beginning-of-line) (point))) (end (progn (end-of-line) - (point)))) + (point))) + (comment-re " *;")) ;; handle block comments here (beginning-of-line) - (if (looking-at " *;") + (if (looking-at comment-re) (progn - (while (and (looking-at " *;") - (> (point) (point-min))) - (forward-line -1)) + (ledger-navigate-skip-lines-backwards comment-re) (setq begin (point)) (goto-char pos) (beginning-of-line) - (while (and (looking-at " *;") - (< (point) (point-max))) - (forward-line 1)) + (ledger-navigate-skip-lines-forwards comment-re) (setq end (point)))) (list begin end))) @@ -166,8 +168,7 @@ Requires empty line separating xacts." (save-excursion (goto-char pos) (beginning-of-line) - (while (looking-at "[ \t]\\|end[[:blank:]]+\\(?:comment\\|test\\)\\_>") - (forward-line -1)) + (ledger-navigate-skip-lines-backwards "[ \t]\\|end[[:blank:]]+\\(?:comment\\|test\\)\\_>") (if (looking-at "[=~0-9\\[]") (ledger-navigate-find-xact-extents pos) (ledger-navigate-find-directive-extents pos)))) -- cgit v1.2.3 From c44c09ebd7e0913d83c313c4ffa8572e81dbe2ec Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Tue, 18 Jun 2019 15:48:53 -0500 Subject: Remove references to setting the month/year for ledger-add-transaction (#180) Closes #170 --- doc/ledger-mode.texi | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi index 555b005..ff19a74 100644 --- a/doc/ledger-mode.texi +++ b/doc/ledger-mode.texi @@ -169,18 +169,12 @@ format. Then type the first few characters of another payee in the search for a Payee that has the same beginning and copy the rest of the transaction to you new entry. -Additionally you can use the ledger @command{xact} command, by either -typing @kbd{C-c C-a} or using @samp{Add Transaction} menu entry. Then -typing a close match to the payee. Ledger-mode will call @command{ledger -xact} with the data you enter and place the transaction in the proper -chronological place in the ledger. - -If you need to add a lot of transactions that are not near your current -date you can set the current year and month so that using @samp{Add -Transaction} will prompt you with a more convenient month and year. To -set the month type @kbd{C-c RET} and enter the month you want. @kbd{C-c -C-y} will prompt you for the year. These settings only effect the -@samp{Add Transaction} command. +Additionally you can use the ledger @command{xact} command, by either typing +@kbd{C-c C-a} or using @samp{Add Transaction} menu entry. Then typing a close +match to the payee. Ledger-mode will call @command{ledger xact} with the data +you enter and place the transaction in the proper chronological place in the +ledger. Subsequent calls to @kbd{C-c C-a} remember the last date so entering +many dates in the past is easy. @node Reconciliation, Reports, Quick Add, Quick Demo @subsection Reconciliation -- cgit v1.2.3 From 1bc6ca27b32cd575d8925d309c8950a6169dd5c2 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Tue, 18 Jun 2019 16:13:19 -0500 Subject: Remove blank lines after ledger-delete-current-transaction (#177) Otherwise when we delete a transaction between two transactions, we're left with a few blank lines instead of just one. --- ledger-xact.el | 3 ++- test/reconcile-test.el | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ledger-xact.el b/ledger-xact.el index cfff4c2..15c3cbd 100644 --- a/ledger-xact.el +++ b/ledger-xact.el @@ -161,7 +161,8 @@ MOMENT is an encoded date" "Delete the transaction surrounging POS." (interactive "d") (let ((bounds (ledger-navigate-find-xact-extents pos))) - (delete-region (car bounds) (cadr bounds)))) + (delete-region (car bounds) (cadr bounds))) + (delete-blank-lines)) (defvar ledger-add-transaction-last-date nil "Last date entered using `ledger-read-transaction'.") diff --git a/test/reconcile-test.el b/test/reconcile-test.el index 4c7c481..289ca16 100644 --- a/test/reconcile-test.el +++ b/test/reconcile-test.el @@ -716,7 +716,7 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=262" (should ;; Expected: this must be ledger buffer (equal (buffer-name) ; current buffer name (buffer-name ledger-buffer))) - (should (= 1323 (point)))))) ; expected on "Book Store" xact + (should (= 1321 (point)))))) ; expected on "Book Store" xact (ert-deftest ledger-reconcile/test-028 () -- cgit v1.2.3 From ea4225c4ec17c279db0f80e434767d046710462d Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Wed, 19 Jun 2019 09:34:19 +1200 Subject: Better fix for allowing reports to be triggered from txns with effective dates This reverts commit f74fb095d7d956b66a8d844ec11db753c7a57c7d, which caused a test regression, and makes a more conservative fix. --- ledger-context.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger-context.el b/ledger-context.el index 5a214d7..0a225c5 100644 --- a/ledger-context.el +++ b/ledger-context.el @@ -39,7 +39,7 @@ (defconst ledger-balance-assertion-string ledger-balance-assertion-regexp) (defconst ledger-comment-string "[ \t]*;[ \t]*\\(.*?\\)") (defconst ledger-nil-string "\\([ \t]+\\)") -(defconst ledger-date-string (concat "^" ledger-full-date-regexp)) +(defconst ledger-date-string "^\\([0-9]\\{4\\}[/-][01]?[0-9][/-][0123]?[0-9]\\)\\(?:=[0-9]\\{4\\}[/-][01]?[0-9][/-][0123]?[0-9]\\)?") (defconst ledger-code-string "\\((.*)\\)?") (defconst ledger-payee-string "\\(.*[^[:space:]]\\)") -- cgit v1.2.3 From 8b7650366dba1769e67477e67db5ec765a427aa2 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Tue, 18 Jun 2019 22:14:04 -0500 Subject: Make ledger-default-date-format an option (#179) Closes #173 --- doc/ledger-mode.texi | 3 ++- ledger-init.el | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi index ff19a74..b531507 100644 --- a/doc/ledger-mode.texi +++ b/doc/ledger-mode.texi @@ -174,7 +174,8 @@ Additionally you can use the ledger @command{xact} command, by either typing match to the payee. Ledger-mode will call @command{ledger xact} with the data you enter and place the transaction in the proper chronological place in the ledger. Subsequent calls to @kbd{C-c C-a} remember the last date so entering -many dates in the past is easy. +many dates in the past is easy. The date format can be changed by modifying +@option{ledger-default-date-format}. @node Reconciliation, Reports, Quick Add, Quick Demo @subsection Reconciliation diff --git a/ledger-init.el b/ledger-init.el index a7c412a..f5d4c3f 100644 --- a/ledger-init.el +++ b/ledger-init.el @@ -37,9 +37,12 @@ Adding the dotted pair (\"decimal-comma\" . t) will tell ledger to treat commas as decimal separator.") -(defvar ledger-default-date-format "%Y/%m/%d" +(defcustom ledger-default-date-format "%Y/%m/%d" "The date format that ledger uses throughout. -Set this to `ledger-iso-date-format' if you prefer ISO 8601 dates.") +Set this to the value of `ledger-iso-date-format' if you prefer +ISO 8601 dates." + :type 'string + :group 'ledger) (defconst ledger-iso-date-format "%Y-%m-%d" "The format for ISO 8601 dates.") -- cgit v1.2.3 From 92d1e22e22334e785a11ecc5be5cce6a892e5dd6 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Mon, 1 Jul 2019 16:25:33 -0500 Subject: Don't kill the report buffer on every new report (#182) Erase the report buffer rather than killing it and recreating it. This allows users to use functions like `display-buffer-reuse-window' to manager where the ledger-report buffer shows up. --- ledger-report.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ledger-report.el b/ledger-report.el index 0de4d5d..89413ed 100644 --- a/ledger-report.el +++ b/ledger-report.el @@ -273,10 +273,10 @@ used to generate the buffer, navigating the buffer, etc." (buf (find-file-noselect file)) (rbuf (get-buffer ledger-report-buffer-name)) (wcfg (current-window-configuration))) - (if rbuf - (kill-buffer rbuf)) (with-current-buffer (pop-to-buffer (get-buffer-create ledger-report-buffer-name)) + (let ((inhibit-read-only t)) + (erase-buffer)) (ledger-report-mode) (set (make-local-variable 'ledger-report-saved) nil) (set (make-local-variable 'ledger-buf) buf) -- cgit v1.2.3 From 78ab0095621150833292dfb2aa0e1338f9044ea7 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Tue, 2 Jul 2019 16:19:36 -0500 Subject: Don't include current line's payee in ledger-payees-in-buffer (#184) Otherwise this makes payee completion difficult. Closes #181 --- ledger-complete.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ledger-complete.el b/ledger-complete.el index e030fbe..a62883f 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -82,15 +82,20 @@ If nil, full account names are offered for completion." (defun ledger-payees-in-buffer () - "Scan buffer and return list of all payees." + "Scan buffer and return list of all payees. +Omit the payee on the current line if it is the only instance of +that payee in the buffer." + ;; We omit the payee on the current line because this function is part of + ;; `ledger-complete'. If we include the current line's payee, then anything + ;; matches, which makes it hard to do completion, see bug#181. (let ((origin (point)) payees-list) (save-excursion (goto-char (point-min)) - (while (re-search-forward - ledger-payee-any-status-regex nil t) ;; matches first line - (unless (and (>= origin (match-beginning 0)) - (< origin (match-end 0))) + (while (re-search-forward ledger-payee-any-status-regex nil t) ;; matches first line + (unless (or (<= (point-at-bol) origin (point-at-eol)) ; current line + (and (>= origin (match-beginning 0)) + (< origin (match-end 0)))) (setq payees-list (cons (match-string-no-properties 3) payees-list))))) ;; add the payee ;; to the list -- cgit v1.2.3 From 739b777ff597d7680778dfb0777f795091392cf0 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Tue, 2 Jul 2019 10:55:58 +1200 Subject: Match account names more liberally for the sake of completion See #141 --- ledger-complete.el | 2 +- ledger-regex.el | 21 ++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/ledger-complete.el b/ledger-complete.el index a62883f..9a2eb04 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -117,7 +117,7 @@ Considers both accounts listed in postings and those declared with \"account\" d (goto-char (point-min)) (let (results) (while (re-search-forward ledger-account-name-or-directive-regex nil t) - (setq results (cons (match-string-no-properties 2) results))) + (setq results (cons (match-string-no-properties 1) results))) (ledger-accounts-deduplicate-sorted (sort results #'ledger-string-greaterp))))) diff --git a/ledger-regex.el b/ledger-regex.el index 9d858c8..e8b004e 100644 --- a/ledger-regex.el +++ b/ledger-regex.el @@ -71,28 +71,23 @@ (defconst ledger-init-string-regex "^--.+?\\($\\|[ ]\\)") -(defconst ledger-account-directive-regex - "^account [ \t]*\\(?2:[^;]+?\\)\\(?3:[ \t]*\\)\\(;.*\\)?$") +(defconst ledger-account-name-regex + "\\([^;[:space:]\r\n]+\\(?: [^;[:space:]\r\n]+\\)*\\)") -(defconst ledger-account-any-status-no-trailing-spaces-regex - "^[ \t]+\\(?1:[*!]\\s-+\\)?[[(]?\\(?2:[^; ].+?\\)[])]?") +(defconst ledger-account-directive-regex + (concat "^account[ \t]+" ledger-account-name-regex)) (defconst ledger-account-any-status-regex - (format "%s%s" - ledger-account-any-status-no-trailing-spaces-regex - "\\(?3:\t\\| [ \t]\\|$\\)")) + (concat "^[[:space:]]+\\(?:[!*][[:space:]]*\\)?" ledger-account-name-regex)) (defconst ledger-account-name-or-directive-regex - (format "\\(?:%s\\|%s\\(?3:\t\\| [ \t]\\)\\)" - ledger-account-directive-regex - ledger-account-any-status-no-trailing-spaces-regex)) + (concat "^\\(?:[[:space:]]+\\(?:[!*][[:space:]]*\\)?\\|account[ \t]+\\)" ledger-account-name-regex)) (defconst ledger-account-pending-regex - "\\(^[ \t]+\\)\\(!\\s-*[^ ].*?\\)\\( \\|\t\\|$\\)") + (concat "\\(^[[:space:]]+\\)!" ledger-account-name-regex)) (defconst ledger-account-cleared-regex - "\\(^[ \t]+\\)\\(*\\s-*[^ ].*?\\)\\( \\|\t\\|$\\)") - + (concat "\\(^[[:space:]]+\\)*" ledger-account-name-regex)) (defmacro ledger-define-regexp (name regex docs &rest args) "Simplify the creation of a Ledger regex and helper functions." -- cgit v1.2.3 From e4e03eea7bff122173d9176bbb676518c0c0486c Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Tue, 2 Jul 2019 11:33:05 +1200 Subject: Tighten up account regex and adjust test expectations --- ledger-regex.el | 15 ++++++++++----- test/complete-test.el | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ledger-regex.el b/ledger-regex.el index e8b004e..c3c431f 100644 --- a/ledger-regex.el +++ b/ledger-regex.el @@ -72,22 +72,27 @@ "^--.+?\\($\\|[ ]\\)") (defconst ledger-account-name-regex - "\\([^;[:space:]\r\n]+\\(?: [^;[:space:]\r\n]+\\)*\\)") + "\\(?1:[^][();[:space:]\r\n]+\\(?: [^][();[:space:]]\r\n]+\\)*\\)") (defconst ledger-account-directive-regex (concat "^account[ \t]+" ledger-account-name-regex)) +(defconst ledger-account-name-maybe-virtual-regex + (concat "[[(]?" ledger-account-name-regex "[])]?")) + (defconst ledger-account-any-status-regex - (concat "^[[:space:]]+\\(?:[!*][[:space:]]*\\)?" ledger-account-name-regex)) + (concat "^[[:space:]]+\\(?:[!*][[:space:]]*\\)?" ledger-account-name-maybe-virtual-regex)) +;; This would incorrectly match "account (foo)", but writing the regexp this way +;; allows us to have just one match result (defconst ledger-account-name-or-directive-regex - (concat "^\\(?:[[:space:]]+\\(?:[!*][[:space:]]*\\)?\\|account[ \t]+\\)" ledger-account-name-regex)) + (format "\\(?:%s\\|%s\\)" ledger-account-any-status-regex ledger-account-directive-regex)) (defconst ledger-account-pending-regex - (concat "\\(^[[:space:]]+\\)!" ledger-account-name-regex)) + (concat "\\(^[[:space:]]+\\)!" ledger-account-name-maybe-virtual-regex)) (defconst ledger-account-cleared-regex - (concat "\\(^[[:space:]]+\\)*" ledger-account-name-regex)) + (concat "\\(^[[:space:]]+\\)*" ledger-account-name-maybe-virtual-regex)) (defmacro ledger-define-regexp (name regex docs &rest args) "Simplify the creation of a Ledger regex and helper functions." diff --git a/test/complete-test.el b/test/complete-test.el index a215549..7d3cb5f 100644 --- a/test/complete-test.el +++ b/test/complete-test.el @@ -87,9 +87,9 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=252" account Expenses:Accomodation account Assets:Cash ; some comment account Assets:Current - alias 1187465S022 +; alias 1187465S022 -- Ideally this line could be uncommented commodity EUR - format 1,000.00 EUR +; format 1,000.00 EUR -- Ideally this line could be uncommented tag ofxid 2018/05/07 * Company Assets:Current -38.33 EUR -- cgit v1.2.3 From a5917bad209ec4d86bdf861fd4fa1e7ec77c40a2 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Thu, 4 Jul 2019 17:28:15 +1200 Subject: Just use built-in delete-dups --- ledger-complete.el | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/ledger-complete.el b/ledger-complete.el index 9a2eb04..3e8ab32 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -101,15 +101,6 @@ that payee in the buffer." ;; to the list (sort (delete-dups payees-list) #'string-lessp))) -(defun ledger-accounts-deduplicate-sorted (l) - "Remove duplicates from a sorted list of strings L." - (let ((current l)) - (while (consp current) - (if (string= (car current) (cadr current)) - (setcdr current (cddr current)) - (pop current))) - l)) - (defun ledger-accounts-list-in-buffer () "Return a list of all known account names in the current buffer as strings. Considers both accounts listed in postings and those declared with \"account\" directives." @@ -118,8 +109,7 @@ Considers both accounts listed in postings and those declared with \"account\" d (let (results) (while (re-search-forward ledger-account-name-or-directive-regex nil t) (setq results (cons (match-string-no-properties 1) results))) - (ledger-accounts-deduplicate-sorted - (sort results #'ledger-string-greaterp))))) + (sort (delete-dups results) #'ledger-string-greaterp)))) (defun ledger-accounts-list () "Return a list of all known account names as strings. -- cgit v1.2.3 From 74091722c6ef5429fc3d87c2132041c28a74d012 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Thu, 4 Jul 2019 18:10:42 +1200 Subject: Sort accounts ascending when completing, not in reverse --- ledger-complete.el | 8 +------- test/complete-test.el | 14 +++++++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/ledger-complete.el b/ledger-complete.el index 3e8ab32..e0c0994 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -24,12 +24,6 @@ (require 'cl-lib) -;; Emacs 24.3 compatibility -(defun ledger-string-greaterp (string1 string2) - "Return non-nil if STRING1 is greater than STRING2 in lexicographic order. -Case is significant." - (string-lessp string2 string1)) - ;; In-place completion support ;;; Code: @@ -109,7 +103,7 @@ Considers both accounts listed in postings and those declared with \"account\" d (let (results) (while (re-search-forward ledger-account-name-or-directive-regex nil t) (setq results (cons (match-string-no-properties 1) results))) - (sort (delete-dups results) #'ledger-string-greaterp)))) + (sort (delete-dups results) #'string-lessp)))) (defun ledger-accounts-list () "Return a list of all known account names as strings. diff --git a/test/complete-test.el b/test/complete-test.el index 7d3cb5f..62fbf4c 100644 --- a/test/complete-test.el +++ b/test/complete-test.el @@ -104,14 +104,14 @@ tag ofxid (insert ledger) (should (equal (ledger-accounts-list-in-buffer) - (list ; I don't know why accounts are sorted in reverse order - "Something" - "Expenses:Utilities:Insurance" - "Expenses:Accomodation" - "Dimensions:Foo" - "Dimensions:Equity" + (list + "Assets:Cash" "Assets:Current" - "Assets:Cash")))))) + "Dimensions:Equity" + "Dimensions:Foo" + "Expenses:Accomodation" + "Expenses:Utilities:Insurance" + "Something")))))) (provide 'complete-test) -- cgit v1.2.3 From 629ce581472910492b8cc3b77963b6a61142a327 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 5 Jul 2019 08:15:45 +1200 Subject: Never include the completion prefix in the candidates list In Emacs 24.3, in particular, the presence of such a candidate causes completion-at-point to simply report that the current symbol is complete. --- ledger-complete.el | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/ledger-complete.el b/ledger-complete.el index e0c0994..1964818 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -248,16 +248,19 @@ Looks in `ledger-accounts-file' if set, otherwise the current buffer." #'ledger-accounts-tree #'ledger-accounts-list)))) (when collection - (list start end - (if (functionp collection) - (completion-table-dynamic (lambda (_) (funcall collection))) - collection) - :exit-function (lambda (&rest _) - (when delete-suffix - (delete-char delete-suffix)) - (when (and realign-after ledger-post-auto-align) - (ledger-post-align-postings (line-beginning-position) (line-end-position)))) - 'ignore)))) + (let ((prefix (buffer-substring-no-properties start end))) + (list start end + (if (functionp collection) + (completion-table-dynamic + (lambda (_) + (cl-remove-if (apply-partially 'string= prefix) (funcall collection)))) + collection) + :exit-function (lambda (&rest _) + (when delete-suffix + (delete-char delete-suffix)) + (when (and realign-after ledger-post-auto-align) + (ledger-post-align-postings (line-beginning-position) (line-end-position)))) + 'ignore))))) (defun ledger-trim-trailing-whitespace (str) (replace-regexp-in-string "[ \t]*$" "" str)) -- cgit v1.2.3 From eac13e8600fdb07e2dd172928c5aca6a3fe4f306 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 5 Jul 2019 08:25:09 +1200 Subject: Add test for #141 --- test/complete-test.el | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/test/complete-test.el b/test/complete-test.el index 62fbf4c..87ff248 100644 --- a/test/complete-test.el +++ b/test/complete-test.el @@ -63,17 +63,17 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=252" :tags '(complete regress) (ledger-tests-with-temp-file - "2010/04/08 payee + "2010/04/08 payee account1 1 € account2 " - (goto-char (point-max)) - (newline) - (insert "2016/09/01 payee") - (ledger-fully-complete-xact) - (should - (equal (buffer-string) - "2010/04/08 payee + (goto-char (point-max)) + (newline) + (insert "2016/09/01 payee") + (ledger-fully-complete-xact) + (should + (equal (buffer-string) + "2010/04/08 payee account1 1 € account2 @@ -82,6 +82,27 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=252" account2 ")))) +(ert-deftest ledger-complete/test-complete-account-without-amount () + "https://github.com/ledger/ledger-mode/issues/141" + :tags '(complete regress) + (ledger-tests-with-temp-file + "2010/04/08 payee + blah 1 € + bloop + +2010/04/09 payee + blo" + (goto-char (point-max)) + (call-interactively 'completion-at-point) + (should + (equal (buffer-string) + "2010/04/08 payee + blah 1 € + bloop + +2010/04/09 payee + bloop")))) + (ert-deftest ledger-complete/test-find-accounts-in-buffer () (let ((ledger "*** Expenses account Expenses:Accomodation -- cgit v1.2.3 From b4df0b62fef356fb826184b88cf70b35541718c3 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 5 Jul 2019 08:35:14 +1200 Subject: Add test and provide different fix for #184. This reverts commit 78ab0095621150833292dfb2aa0e1338f9044ea7. This is now fixed more generally by 629ce581. --- ledger-complete.el | 15 +++++---------- test/complete-test.el | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ledger-complete.el b/ledger-complete.el index 1964818..569031e 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -76,20 +76,15 @@ If nil, full account names are offered for completion." (defun ledger-payees-in-buffer () - "Scan buffer and return list of all payees. -Omit the payee on the current line if it is the only instance of -that payee in the buffer." - ;; We omit the payee on the current line because this function is part of - ;; `ledger-complete'. If we include the current line's payee, then anything - ;; matches, which makes it hard to do completion, see bug#181. + "Scan buffer and return list of all payees." (let ((origin (point)) payees-list) (save-excursion (goto-char (point-min)) - (while (re-search-forward ledger-payee-any-status-regex nil t) ;; matches first line - (unless (or (<= (point-at-bol) origin (point-at-eol)) ; current line - (and (>= origin (match-beginning 0)) - (< origin (match-end 0)))) + (while (re-search-forward + ledger-payee-any-status-regex nil t) ;; matches first line + (unless (and (>= origin (match-beginning 0)) + (< origin (match-end 0))) (setq payees-list (cons (match-string-no-properties 3) payees-list))))) ;; add the payee ;; to the list diff --git a/test/complete-test.el b/test/complete-test.el index 87ff248..368f5b9 100644 --- a/test/complete-test.el +++ b/test/complete-test.el @@ -103,6 +103,25 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=252" 2010/04/09 payee bloop")))) +(ert-deftest ledger-complete/test-complete-single-payee () + "https://github.com/ledger/ledger-mode/issues/181" + :tags '(complete regress) + (ledger-tests-with-temp-file + "2019/06/28 Foobar + Expenses:Baz 11.99 CAD + Assets:Cash + +2019/06/20 Foo" + (goto-char (point-max)) + (call-interactively 'completion-at-point) + (should + (equal (buffer-string) + "2019/06/28 Foobar + Expenses:Baz 11.99 CAD + Assets:Cash + +2019/06/20 Foobar")))) + (ert-deftest ledger-complete/test-find-accounts-in-buffer () (let ((ledger "*** Expenses account Expenses:Accomodation -- cgit v1.2.3 From 80d808b7876b5b5a3195372d73626bae5812fdc7 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 5 Jul 2019 22:41:49 +1200 Subject: Fix account regex to correctly match account names which contain spaces Fixes #185 --- ledger-regex.el | 2 +- test/complete-test.el | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ledger-regex.el b/ledger-regex.el index c3c431f..b083f8a 100644 --- a/ledger-regex.el +++ b/ledger-regex.el @@ -72,7 +72,7 @@ "^--.+?\\($\\|[ ]\\)") (defconst ledger-account-name-regex - "\\(?1:[^][();[:space:]\r\n]+\\(?: [^][();[:space:]]\r\n]+\\)*\\)") + "\\(?1:[^][();[:space:]\r\n]+\\(?: [^][();[:space:]\r\n]+\\)*\\)") (defconst ledger-account-directive-regex (concat "^account[ \t]+" ledger-account-name-regex)) diff --git a/test/complete-test.el b/test/complete-test.el index 368f5b9..d5082ce 100644 --- a/test/complete-test.el +++ b/test/complete-test.el @@ -153,6 +153,16 @@ tag ofxid "Expenses:Utilities:Insurance" "Something")))))) +(ert-deftest ledger-complete/test-find-accounts-with-spaces-in-buffer () + (let ((ledger "*** Expenses +account Expenses:The Bakery +")) + (with-temp-buffer + (insert ledger) + (should (equal + (ledger-accounts-list-in-buffer) + (list + "Expenses:The Bakery")))))) (provide 'complete-test) -- cgit v1.2.3 From 0c18566a61ea767aadef1e7b52f21150d8618cc4 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Fri, 5 Jul 2019 15:11:53 -0500 Subject: Remove unused lexical variable --- ledger-report.el | 1 - 1 file changed, 1 deletion(-) diff --git a/ledger-report.el b/ledger-report.el index 89413ed..25f22d9 100644 --- a/ledger-report.el +++ b/ledger-report.el @@ -271,7 +271,6 @@ used to generate the buffer, navigating the buffer, etc." (list rname edit)))) (let* ((file (ledger-master-file)) (buf (find-file-noselect file)) - (rbuf (get-buffer ledger-report-buffer-name)) (wcfg (current-window-configuration))) (with-current-buffer (pop-to-buffer (get-buffer-create ledger-report-buffer-name)) -- cgit v1.2.3 From 08462cdf1e9c58c45ce3d4909bed7e69a25ed52c Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Tue, 9 Jul 2019 17:47:59 +1200 Subject: Avoid [[:space]] in regexes, which can be affected by the syntax table Fixes #187 --- ledger-regex.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ledger-regex.el b/ledger-regex.el index b083f8a..38fd00b 100644 --- a/ledger-regex.el +++ b/ledger-regex.el @@ -72,7 +72,7 @@ "^--.+?\\($\\|[ ]\\)") (defconst ledger-account-name-regex - "\\(?1:[^][();[:space:]\r\n]+\\(?: [^][();[:space:]\r\n]+\\)*\\)") + "\\(?1:[^][(); \t\r\n]+\\(?: [^][(); \t\r\n]+\\)*\\)") (defconst ledger-account-directive-regex (concat "^account[ \t]+" ledger-account-name-regex)) @@ -81,7 +81,7 @@ (concat "[[(]?" ledger-account-name-regex "[])]?")) (defconst ledger-account-any-status-regex - (concat "^[[:space:]]+\\(?:[!*][[:space:]]*\\)?" ledger-account-name-maybe-virtual-regex)) + (concat "^[ \t]+\\(?:[!*][ \t]*\\)?" ledger-account-name-maybe-virtual-regex)) ;; This would incorrectly match "account (foo)", but writing the regexp this way ;; allows us to have just one match result @@ -89,10 +89,10 @@ (format "\\(?:%s\\|%s\\)" ledger-account-any-status-regex ledger-account-directive-regex)) (defconst ledger-account-pending-regex - (concat "\\(^[[:space:]]+\\)!" ledger-account-name-maybe-virtual-regex)) + (concat "\\(^[ \t]+\\)!" ledger-account-name-maybe-virtual-regex)) (defconst ledger-account-cleared-regex - (concat "\\(^[[:space:]]+\\)*" ledger-account-name-maybe-virtual-regex)) + (concat "\\(^[ \t]+\\)*" ledger-account-name-maybe-virtual-regex)) (defmacro ledger-define-regexp (name regex docs &rest args) "Simplify the creation of a Ledger regex and helper functions." -- cgit v1.2.3 From 675a13713a66d21ba36f984f21b3fc32fc66384d Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Tue, 9 Jul 2019 08:53:05 -0500 Subject: Switch CI to use EVM --- .travis.yml | 66 +++++++++++------------------------------- ledger-flymake.el | 4 +++ tools/travis-install-ledger.sh | 48 ------------------------------ 3 files changed, 21 insertions(+), 97 deletions(-) delete mode 100755 tools/travis-install-ledger.sh diff --git a/.travis.yml b/.travis.yml index edadf85..9209c46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,64 +1,32 @@ sudo: required - language: generic - -cache: - directories: - - ledger-master - - ledger-next - -os: - - linux - # - osx # Travis is saturated; see https://www.traviscistatus.com/ +dist: xenial env: matrix: - - EMACS_VERSION=emacs24 LEDGER_BRANCH=master - # - EMACS_VERSION=emacs24 LEDGER_BRANCH=apt-get # apt-get's ledger is too old - - EMACS_VERSION=emacs-snapshot LEDGER_BRANCH=next - -matrix: - allow_failures: - - env: EMACS_VERSION=emacs-snapshot LEDGER_BRANCH=next + - EVM_EMACS=emacs-24.3-travis + - EVM_EMACS=emacs-25.1-travis + # EVM doesn't support xenial yet, which we need since it has ledger version 3. + # See https://github.com/rejeep/evm/issues/125 + # - EVM_EMACS=emacs-26.1-travis + # - EVM_EMACS=emacs-26.2-travis + # - EVM_EMACS=emacs-git-snapshot-travis before_install: - - ./tools/travis-install-ledger.sh $LEDGER_BRANCH - - if [ "$TRAVIS_OS_NAME" = "linux" ]; then - export PATH=$TRAVIS_BUILD_DIR/ledger-$LEDGER_BRANCH:$PATH; - fi - -install: - - if [ "$TRAVIS_OS_NAME-$EMACS_VERSION" = "linux-emacs24" ]; then - sudo add-apt-repository -y ppa:cassou/emacs && - sudo apt-get -qq update && - sudo apt-get -qq install emacs24 emacs24-el && - export EMACS=/usr/bin/emacs; - fi - - if [ "$TRAVIS_OS_NAME-$EMACS_VERSION" = "linux-emacs-snapshot" ]; then - sudo add-apt-repository -y ppa:ubuntu-elisp/ppa && - sudo apt-get -qq update && - sudo apt-get -qq install emacs-snapshot && - export EMACS=/usr/bin/emacs-snapshot; - fi - - if [ "$TRAVIS_OS_NAME-$EMACS_VERSION" = "osx-emacs24" ]; then - wget https://emacsformacosx.com/emacs-builds/Emacs-24.4-universal.dmg && - hdiutil attach Emacs-24.4-universal.dmg && - export EMACS=/Volumes/Emacs/Emacs.app/Contents/MacOS/Emacs; - fi - - if [ "$TRAVIS_OS_NAME-$EMACS_VERSION" = "osx-emacs25" ]; then - wget https://emacsformacosx.com/emacs-builds/Emacs-25.1-universal.dmg && - hdiutil attach Emacs-25.1-universal.dmg && - export EMACS=/Volumes/Emacs/Emacs.app/Contents/MacOS/Emacs; - fi + - sudo apt-get install -y ledger + - git clone https://github.com/rejeep/evm.git $HOME/.evm + - export PATH=$HOME/.evm/bin:$PATH + - evm config path /tmp + - evm install $EVM_EMACS --use --skip script: - - $EMACS --version + - emacs --version - ledger --version - - $EMACS --eval "(setq byte-compile-error-on-warn (>= emacs-major-version 25))" -L . --batch -f batch-byte-compile ledger-*.el - - cd test && make test-batch EMACS="$EMACS" + - emacs --eval "(setq byte-compile-error-on-warn (>= emacs-major-version 25))" -L . --batch -f batch-byte-compile *.el + - make -C test test-batch after_script: - - make checkdoc + - make -C test checkdoc notifications: email: false diff --git a/ledger-flymake.el b/ledger-flymake.el index 06bddd7..182efd7 100644 --- a/ledger-flymake.el +++ b/ledger-flymake.el @@ -29,6 +29,10 @@ (require 'flymake) (require 'ledger-exec) ; for `ledger-binary-path' +;; To silence byte compiler warnings in Emacs 25 and older: +(declare-function flymake-diag-region "flymake" (buffer line &optional col)) +(declare-function flymake-make-diagnostic "flymake" (buffer beg end type text &optional data overlay-properties)) + (defvar-local ledger--flymake-proc nil) (defcustom ledger-flymake-be-pedantic nil diff --git a/tools/travis-install-ledger.sh b/tools/travis-install-ledger.sh deleted file mode 100755 index e30ba3b..0000000 --- a/tools/travis-install-ledger.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash - -set -eu -o pipefail -set -o xtrace - -BRANCH=$1 -LAST_BUILD_FILE=travis-last-build - -if [ "${TRAVIS_OS_NAME}" = "linux" ]; then - if [ "${BRANCH}" = "apt-get" ]; then - sudo apt-get update -qq - sudo apt-get install -qq ledger - else - sudo apt-get install -qq git - sudo apt-get install -qq libboost-all-dev # ledger needs Boost's runtime libraries - sudo apt-get install -qq libgmp-dev libmpfr-dev libedit-dev - - if [ ! -d "ledger-$BRANCH/.git" ]; then - git clone --depth 1 -b "$BRANCH" "https://github.com/ledger/ledger/" "ledger-$BRANCH" - fi - - cd "ledger-$BRANCH" - - git fetch origin - git reset --hard "origin/$BRANCH" - - REV="$(git rev-parse "$BRANCH")" - - if [ "$(cat "$LAST_BUILD_FILE" 2> /dev/null)" = "$REV" ]; then - echo "Build is up to date" - else - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - sudo apt-get update -qq - sudo apt-get install -qq gcc-4.8 g++-4.8 - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 90 - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90 - - cmake . - make -j2 - echo "$REV" > "$LAST_BUILD_FILE" - fi - fi -fi - -if [ "${TRAVIS_OS_NAME}" = "osx" ]; then - brew update - brew install ledger -fi -- cgit v1.2.3 From 69234f5611d5962a3e9df07a01166e4c08297c92 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Tue, 16 Jul 2019 10:03:20 -0500 Subject: Silence the byte compiler --- ledger-commodities.el | 1 + ledger-exec.el | 2 ++ ledger-regex.el | 2 ++ ledger-xact.el | 3 ++- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ledger-commodities.el b/ledger-commodities.el index 823f045..beb4759 100644 --- a/ledger-commodities.el +++ b/ledger-commodities.el @@ -31,6 +31,7 @@ ;; These keep the byte-compiler from warning about them, but have no other ;; effect: (defvar ledger-environment-alist) +(declare-function ledger-exec-ledger "ledger-exec" (input-buffer &optional output-buffer &rest args)) (defcustom ledger-reconcile-default-commodity "$" "The default commodity for use in target calculations in ledger reconcile." diff --git a/ledger-exec.el b/ledger-exec.el index 158638e..84e52b8 100644 --- a/ledger-exec.el +++ b/ledger-exec.el @@ -25,6 +25,8 @@ ;;; Code: +(declare-function ledger-master-file "ledger-report" ()) + (defconst ledger-version-needed "3.0.0" "The version of ledger executable needed for interactive features.") diff --git a/ledger-regex.el b/ledger-regex.el index 38fd00b..8ac3002 100644 --- a/ledger-regex.el +++ b/ledger-regex.el @@ -22,6 +22,8 @@ (require 'rx) (require 'cl-lib) +(defvar ledger-iso-date-regex) + (defconst ledger-amount-regex (concat "\\( \\|\t\\| \t\\)[ \t]*-?" "\\([A-Z$€£₹_(]+ *\\)?" diff --git a/ledger-xact.el b/ledger-xact.el index 15c3cbd..f8fb216 100644 --- a/ledger-xact.el +++ b/ledger-xact.el @@ -30,7 +30,8 @@ (require 'ledger-navigate) (require 'ledger-exec) (require 'ledger-post) -(declare-function ledger-read-date "ledger-mode") +(declare-function ledger-read-date "ledger-mode" (prompt)) +(declare-function ledger-format-date "ledger-init" (&optional date)) ;; TODO: This file depends on code in ledger-mode.el, which depends on this. -- cgit v1.2.3 From 896515d2237751d7070e7ac7fad7327c2809516b Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Sat, 3 Aug 2019 16:00:02 -0500 Subject: New commands ledger-navigate-{next/previous}-uncleared bug#190 --- ledger-navigate.el | 20 ++++++++++++++++++++ test/navigate-test.el | 28 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/ledger-navigate.el b/ledger-navigate.el index a96f4b5..811662c 100644 --- a/ledger-navigate.el +++ b/ledger-navigate.el @@ -173,6 +173,26 @@ Requires empty line separating xacts." (ledger-navigate-find-xact-extents pos) (ledger-navigate-find-directive-extents pos)))) +(defun ledger-navigate-next-uncleared () + "Move point to the next uncleared transaction." + (interactive) + (when (looking-at ledger-payee-uncleared-regex) + (forward-line)) + (if (re-search-forward ledger-payee-uncleared-regex nil t) + (progn (beginning-of-line) + (point)) + (user-error "No next uncleared transactions"))) + +(defun ledger-navigate-previous-uncleared () + "Move point to the previous uncleared transaction." + (interactive) + (when (equal (car (ledger-context-at-point)) 'acct-transaction) + (ledger-navigate-beginning-of-xact)) + (if (re-search-backward ledger-payee-uncleared-regex nil t) + (progn (beginning-of-line) + (point)) + (user-error "No previous uncleared transactions"))) + (provide 'ledger-navigate) diff --git a/test/navigate-test.el b/test/navigate-test.el index 84656b1..503dbc8 100644 --- a/test/navigate-test.el +++ b/test/navigate-test.el @@ -43,6 +43,34 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=441" (ledger-navigate-prev-xact-or-directive) (should (eq 104 (point))))) +(ert-deftest ledger-navigate-uncleared () + :tags '(navigate) + (with-temp-buffer + (insert + "2011/01/27 Book Store + Expenses:Books $20.00 + Liabilities:MasterCard + +2011/04/25 * Tom's Used Cars + Expenses:Auto $ 5,500.00 + Assets:Checking + +2011/04/27 Bookstore + Expenses:Books $20.00 + Assets:Checking + +2011/12/01 * Sale + Assets:Checking $ 30.00 + Income:Sales") + (ledger-mode) + (goto-char (point-min)) + (ledger-navigate-next-uncleared) + (should (looking-at-p (regexp-quote "2011/04/27 Bookstore"))) + (should-error (ledger-navigate-next-uncleared)) + (ledger-navigate-previous-uncleared) + (should (bobp)) + )) + (provide 'navigate-test) -- cgit v1.2.3 From 5067e40805c40e83424d206584838ffa8c8117c7 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Thu, 29 Aug 2019 11:32:46 -0500 Subject: Add documentation on navigation commands --- doc/ledger-mode.texi | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi index b531507..1a5674d 100644 --- a/doc/ledger-mode.texi +++ b/doc/ledger-mode.texi @@ -249,6 +249,7 @@ current regex. Cancel the narrowing by typing @kbd{C-c C-f} again. @chapter The Ledger Buffer @menu +* Navigating Transactions:: * Adding Transactions:: * Copying Transactions:: * Editing Amounts:: @@ -259,8 +260,28 @@ current regex. Cancel the narrowing by typing @kbd{C-c C-f} again. * Narrowing Transactions:: @end menu +@node Navigating Transactions, Adding Transactions, The Ledger Buffer, The Ledger Buffer +@section Navigating Transactions +@cindex transaction, navigation -@node Adding Transactions, Copying Transactions, The Ledger Buffer, The Ledger Buffer +@findex ledger-navigate-next-xact-or-directive +@findex ledger-navigate-prev-xact-or-directive +@kindex M-p +@kindex M-n + +In addition to the usual Emacs navigation commands, ledger-mode offers several +additional commands to ease navigation. @kbd{M-n} and @kbd{M-p} navigate between +next and previous xacts or directives. + +@findex ledger-navigate-next-uncleared +@findex ledger-navigate-previous-uncleared + +Additionally, M-x ledger-navigate-previous-uncleared and M-x +ledger-navigate-next-uncleared navigate to the next and precious uncleared +transactions. + + +@node Adding Transactions, Copying Transactions, Navigating Transactions, The Ledger Buffer @section Adding Transactions @findex ledger-post-amount-alignment-column @kindex TAB -- cgit v1.2.3