summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/ledger-mode.texi5
-rw-r--r--doc/ledger3.texi4
-rw-r--r--lisp/ledger-complete.el74
-rw-r--r--lisp/ledger-context.el47
-rw-r--r--lisp/ledger-mode.el2
-rw-r--r--lisp/ledger-post.el124
-rw-r--r--lisp/ledger-regex.el4
-rw-r--r--src/report.h2
8 files changed, 111 insertions, 151 deletions
diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi
index e81045c6..c8af96cb 100644
--- a/doc/ledger-mode.texi
+++ b/doc/ledger-mode.texi
@@ -175,11 +175,6 @@ 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.
-To complete just the part of the transaction where your cursor is at,
-Ledger-mode supports Emacs' universal @command{completion-at-point}
-command. You may bind this command to @kbd{C-M-i} since this is the
-default for Emacs programming modes.
-
@node Reconciliation, Reports, Quick Add, Quick Demo
@subsection Reconciliation
@kindex C-c C-r
diff --git a/doc/ledger3.texi b/doc/ledger3.texi
index 4e544ef3..2b962180 100644
--- a/doc/ledger3.texi
+++ b/doc/ledger3.texi
@@ -5833,7 +5833,7 @@ Strings}). The default is:
"%(quoted(code)),"
"%(quoted(payee)),"
"%(quoted(display_account)),"
-"%(quoted(commodity)),"
+"%(quoted(commodity(scrub(display_amount)))),"
"%(quoted(quantity(scrub(display_amount)))),"
"%(quoted(cleared ? \"*\" : (pending ? \"!\" : \"\"))),"
"%(quoted(join(note | xact.note)))\n"
@@ -6780,7 +6780,7 @@ Set the format for @command{csv} reports. The default is:
%(quoted(code)),
%(quoted(payee)),
%(quoted(display_account)),
- %(quoted(commodity)),
+ %(quoted(commodity(scrub(display_amount)))),
%(quoted(quantity(scrub(display_amount)))),
%(quoted(cleared ? \"*\" : (pending ? \"!\" : \"\"))),
%(quoted(join(note | xact.note)))\n"
diff --git a/lisp/ledger-complete.el b/lisp/ledger-complete.el
index 5bb69dc2..effee060 100644
--- a/lisp/ledger-complete.el
+++ b/lisp/ledger-complete.el
@@ -145,38 +145,9 @@ Return list."
(cdr root))
'string-lessp))))
-(defun ledger-command-at-point ()
- "Do appropriate completion for current context."
- (let ((context (mapcar*
- (lambda(x) (if (symbolp x) (symbol-name x)))
- (ledger-context-at-point))))
- (cond
- ((string= "acct-transaction" (car context))
- (concat (car context) "/" (nth 1 context)))
- ((string= "pmnt-transaction" (car context))
- (concat (car context) "/" (nth 1 context)))
- (t
- (car context)))))
-
(defun ledger-complete-at-point ()
- "Calls the right completion function for first argument completions."
- (ignore
- (funcall (or (pcomplete-find-completion-function
- (ledger-command-at-point))
- pcomplete-default-completion-function))))
-
-(defun pcomplete/ledger-mode/empty-line ()
- "Complete when at empty line."
- (ignore
- (ledger-add-transaction (read-string "Transaction: "
- (ledger-year-and-month)) (point))))
-
-(defun pcomplete/ledger-mode/pmnt-transaction/date ()
- "Complete when at date in transaction."
- (ignore))
-
-(defun pcomplete/ledger-mode/pmnt-transaction/payee ()
- "Complete when at payee in transaction."
+ "Do appropriate completion for the thing at point."
+ (interactive)
(while (pcomplete-here
(if (eq (save-excursion
(ledger-thing-at-point)) 'transaction)
@@ -197,42 +168,31 @@ Return list."
(goto-char (line-end-position))
(search-backward ";" (line-beginning-position) t)
(skip-chars-backward " \t0123456789.,")
- (throw 'pcompleted t)))))))
-
-(defun pcomplete/ledger-mode/acct-transaction/indent ()
- "Complete when at indent in transaction."
- (ignore (ledger-thing-at-point)))
-
-(defun pcomplete/ledger-mode/acct-transaction/account ()
- "Complete when at account in transaction."
- (set (make-local-variable 'pcomplete-termination-string) " ")
- (pcomplete-here (ledger-accounts)))
-
-(defun pcomplete/ledger-mode/acct-transaction/amount ()
- "Complete when at amount in transaction."
- (ignore (ledger-post-edit-amount)))
+ (throw 'pcompleted t)))
+ (ledger-accounts)))))
-(defun pcomplete/ledger-mode/acct-transaction/comment ()
- "Complete when at amount in transaction."
- (pcomplete-here (ledger-find-metadata-in-buffer)))
+(defun ledger-trim-trailing-whitespace (str)
+ (let ((s str))
+ (when (string-match "[ \t]*$" s)
+ (replace-match "" nil nil s))))
(defun ledger-fully-complete-xact ()
"Completes a transaction if there is another matching payee in the buffer.
Does not use ledger xact"
(interactive)
- (let* ((name (caar (ledger-parse-arguments)))
- (rest-of-name name)
- xacts)
+ (let* ((name (ledger-trim-trailing-whitespace (caar (ledger-parse-arguments))))
+ (rest-of-name name)
+ xacts)
(save-excursion
(when (eq 'transaction (ledger-thing-at-point))
- (delete-region (point) (+ (length name) (point)))
- ;; Search backward for a matching payee
+ (delete-region (point) (+ (length name) (point)))
+ ;; Search backward for a matching payee
(when (re-search-backward
(concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+\\(.*"
(regexp-quote name) ".*\\)" ) nil t)
- (setq rest-of-name (match-string 3))
+ (setq rest-of-name (match-string 3))
;; Start copying the postings
- (forward-line)
+ (forward-line)
(while (looking-at ledger-account-any-status-regex)
(setq xacts (cons (buffer-substring-no-properties
(line-beginning-position)
@@ -243,7 +203,7 @@ Does not use ledger xact"
;; Insert rest-of-name and the postings
(when xacts
(save-excursion
- (insert rest-of-name ?\n)
+ (insert rest-of-name ?\n)
(while xacts
(insert (car xacts) ?\n)
(setq xacts (cdr xacts))))
@@ -266,7 +226,7 @@ ledger-magic-tab would cycle properly"
pcomplete-expand-and-complete
pcomplete-reverse)))
(progn
- (delete-char pcomplete-last-completion-length)
+ (delete-backward-char pcomplete-last-completion-length)
(if (eq this-command 'pcomplete-reverse)
(progn
(push (car (last pcomplete-current-completions))
diff --git a/lisp/ledger-context.el b/lisp/ledger-context.el
index e9b1264b..44ad3a30 100644
--- a/lisp/ledger-context.el
+++ b/lisp/ledger-context.el
@@ -42,7 +42,16 @@
(defconst ledger-code-string "\\((.*)\\)?")
(defconst ledger-payee-string "\\(.*\\)")
-(defmacro ledger-single-line-config (&rest elements)
+(defmacro ledger-line-regex (&rest elements)
+ (let (regex-string)
+ (concat (dolist (e elements regex-string)
+ (setq regex-string
+ (concat regex-string
+ (eval
+ (intern
+ (concat "ledger-" (symbol-name e) "-string")))))) "[ \t]*$")))
+
+(defmacro ledger-single-line-config2 (&rest elements)
"Take list of ELEMENTS and return regex and element list for use in context-at-point"
(let (regex-string)
`'(,(concat (dolist (e elements regex-string)
@@ -53,25 +62,23 @@
(concat "ledger-" (symbol-name e) "-string")))))) "[ \t]*$")
,elements)))
+(defmacro ledger-single-line-config (&rest elements)
+ "Take list of ELEMENTS and return regex and element list for use in context-at-point"
+ `'(,(eval `(ledger-line-regex ,@elements))
+ ,elements))
+
(defconst ledger-line-config
- (list
- (list 'pmnt-transaction
- (list (ledger-single-line-config date nil status nil code nil payee nil comment)
- (ledger-single-line-config date nil status nil code nil payee)
- (ledger-single-line-config date nil status nil payee)
- (ledger-single-line-config date nil code nil payee nil comment)
- (ledger-single-line-config date nil code nil payee)
- (ledger-single-line-config date nil payee)
- (ledger-single-line-config date)))
- (list 'acct-transaction
- (list (ledger-single-line-config indent comment)
- (ledger-single-line-config indent status account nil commodity amount nil comment)
- (ledger-single-line-config indent status account nil commodity amount)
- (ledger-single-line-config indent status account nil amount nil commodity comment)
- (ledger-single-line-config indent status account nil amount nil commodity)
- (ledger-single-line-config indent status account nil amount)
- (ledger-single-line-config indent status account nil comment)
- (ledger-single-line-config indent status account)))))
+ (list (list 'xact (list (ledger-single-line-config date nil status nil code nil payee nil comment)
+ (ledger-single-line-config date nil status nil code nil payee)
+ (ledger-single-line-config date nil status nil payee)))
+ (list 'acct-transaction (list (ledger-single-line-config indent comment)
+ (ledger-single-line-config2 indent status account nil commodity amount nil comment)
+ (ledger-single-line-config2 indent status account nil commodity amount)
+ (ledger-single-line-config2 indent status account nil amount nil commodity comment)
+ (ledger-single-line-config2 indent status account nil amount nil commodity)
+ (ledger-single-line-config2 indent status account nil amount)
+ (ledger-single-line-config2 indent status account nil comment)
+ (ledger-single-line-config2 indent status account)))))
(defun ledger-extract-context-info (line-type pos)
"Get context info for current line with LINE-TYPE.
@@ -131,7 +138,7 @@ the fields in the line in a association list."
((memq first-char '(?\ ?\t))
(ledger-extract-context-info 'acct-transaction pos))
((memq first-char '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
- (ledger-extract-context-info 'pmnt-transaction pos))
+ (ledger-extract-context-info 'xact pos))
((equal first-char ?\=)
'(automated-xact nil nil))
((equal first-char ?\~)
diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el
index 27f8893b..6eb0aaa5 100644
--- a/lisp/ledger-mode.el
+++ b/lisp/ledger-mode.el
@@ -336,7 +336,7 @@ With a prefix argument, remove the effective date. "
'ledger-parse-arguments)
(set (make-local-variable 'pcomplete-command-completion-function)
'ledger-complete-at-point)
- (add-to-list 'completion-at-point-functions 'pcomplete-completions-at-point)
+ (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
(add-hook 'post-command-hook 'ledger-highlight-xact-under-point nil t)
(add-hook 'before-revert-hook 'ledger-occur-remove-all-overlays nil t)
diff --git a/lisp/ledger-post.el b/lisp/ledger-post.el
index d67b7ca0..dac3f736 100644
--- a/lisp/ledger-post.el
+++ b/lisp/ledger-post.el
@@ -45,8 +45,8 @@
"Which completion engine to use, :iswitchb or :ido chose those engines,
:built-in uses built-in Ledger-mode completion"
:type '(radio (const :tag "built in completion" :built-in)
- (const :tag "ido completion" :ido)
- (const :tag "iswitchb completion" :iswitchb) )
+ (const :tag "ido completion" :ido)
+ (const :tag "iswitchb completion" :iswitchb) )
:group 'ledger-post)
(defun ledger-post-all-accounts ()
@@ -72,15 +72,15 @@
PROMPT is a string to prompt with. CHOICES is a list of strings
to choose from."
(cond ((eq ledger-post-use-completion-engine :iswitchb)
- (let* ((iswitchb-use-virtual-buffers nil)
- (iswitchb-make-buflist-hook
- (lambda ()
- (setq iswitchb-temp-buflist choices))))
- (iswitchb-read-buffer prompt)))
- ((eq ledger-post-use-completion-engine :ido)
- (ido-completing-read prompt choices))
- (t
- (completing-read prompt choices))))
+ (let* ((iswitchb-use-virtual-buffers nil)
+ (iswitchb-make-buflist-hook
+ (lambda ()
+ (setq iswitchb-temp-buflist choices))))
+ (iswitchb-read-buffer prompt)))
+ ((eq ledger-post-use-completion-engine :ido)
+ (ido-completing-read prompt choices))
+ (t
+ (completing-read prompt choices))))
(defvar ledger-post-current-list nil)
@@ -102,12 +102,12 @@ to choose from."
(match-end ledger-regex-post-line-group-account))
(insert account)
(cond
- ((> existing-len account-len)
- (insert (make-string (- existing-len account-len) ? )))
- ((< existing-len account-len)
- (dotimes (n (- account-len existing-len))
- (if (looking-at "[ \t]\\( [ \t]\\|\t\\)")
- (delete-char 1)))))))
+ ((> existing-len account-len)
+ (insert (make-string (- existing-len account-len) ? )))
+ ((< existing-len account-len)
+ (dotimes (n (- account-len existing-len))
+ (if (looking-at "[ \t]\\( [ \t]\\|\t\\)")
+ (delete-char 1)))))))
(goto-char pos)))
@@ -131,11 +131,11 @@ Return the column of the beginning of the account and leave point
at beginning of account"
(if (> end (point))
(when (re-search-forward ledger-account-any-status-regex (1+ end) t)
- ;; the 1+ is to make sure we can catch the newline
- (if (match-beginning 1)
- (goto-char (match-beginning 1))
- (goto-char (match-beginning 2)))
- (current-column))))
+ ;; the 1+ is to make sure we can catch the newline
+ (if (match-beginning 1)
+ (goto-char (match-beginning 1))
+ (goto-char (match-beginning 2)))
+ (current-column))))
(defun ledger-post-align-xact (pos)
(interactive "d")
@@ -150,52 +150,52 @@ region align the posting on the current line."
(save-excursion
(if (or (not (mark))
- (not (use-region-p)))
- (set-mark (point)))
+ (not (use-region-p)))
+ (set-mark (point)))
(let* ((inhibit-modification-hooks t)
- (mark-first (< (mark) (point)))
- (begin-region (if beg
- beg
- (if mark-first (mark) (point))))
- (end-region (if end
- end
- (if mark-first (point) (mark))))
- acct-start-column acct-end-column acct-adjust amt-width
- (lines-left 1))
+ (mark-first (< (mark) (point)))
+ (begin-region (if beg
+ beg
+ (if mark-first (mark) (point))))
+ (end-region (if end
+ end
+ (if mark-first (point) (mark))))
+ acct-start-column acct-end-column acct-adjust amt-width
+ (lines-left 1))
;; Condition point and mark to the beginning and end of lines
(goto-char end-region)
(setq end-region (line-end-position))
(goto-char begin-region)
(goto-char
(setq begin-region
- (line-beginning-position)))
+ (line-beginning-position)))
;; This is the guts of the alignment loop
(while (and (or (setq acct-start-column (ledger-next-account (line-end-position)))
- lines-left)
- (< (point) end-region))
- (when acct-start-column
- (setq acct-end-column (save-excursion
- (goto-char (match-end 2))
- (current-column)))
- (when (/= (setq acct-adjust (- ledger-post-account-alignment-column acct-start-column)) 0)
- (setq acct-end-column (+ acct-end-column acct-adjust)) ;;adjust the account ending column
- (if (> acct-adjust 0)
- (insert (make-string acct-adjust ? ))
- (delete-char acct-adjust)))
- (when (setq amt-width (ledger-next-amount (line-end-position)))
- (if (/= 0 (setq amt-adjust (- (if (> (- ledger-post-amount-alignment-column amt-width)
- (+ 2 acct-end-column))
- ledger-post-amount-alignment-column ;;we have room
- (+ acct-end-column 2 amt-width))
- amt-width
- (current-column))))
- (if (> amt-adjust 0)
- (insert (make-string amt-adjust ? ))
- (delete-char amt-adjust)))))
- (forward-line)
- (setq lines-left (not (eobp))))
+ lines-left)
+ (< (point) end-region))
+ (when acct-start-column
+ (setq acct-end-column (save-excursion
+ (goto-char (match-end 2))
+ (current-column)))
+ (when (/= (setq acct-adjust (- ledger-post-account-alignment-column acct-start-column)) 0)
+ (setq acct-end-column (+ acct-end-column acct-adjust)) ;;adjust the account ending column
+ (if (> acct-adjust 0)
+ (insert (make-string acct-adjust ? ))
+ (delete-char acct-adjust)))
+ (when (setq amt-width (ledger-next-amount (line-end-position)))
+ (if (/= 0 (setq amt-adjust (- (if (> (- ledger-post-amount-alignment-column amt-width)
+ (+ 2 acct-end-column))
+ ledger-post-amount-alignment-column ;;we have room
+ (+ acct-end-column 2 amt-width))
+ amt-width
+ (current-column))))
+ (if (> amt-adjust 0)
+ (insert (make-string amt-adjust ? ))
+ (delete-char amt-adjust)))))
+ (forward-line)
+ (setq lines-left (not (eobp))))
(setq inhibit-modification-hooks nil))))
@@ -214,11 +214,11 @@ region align the posting on the current line."
(delete-region (match-beginning 0) (match-end 0))
(calc)
(calc-eval val-string 'push)) ;; edit the amount
- (progn ;;make sure there are two spaces after the account name and go to calc
- (if (search-backward " " (- (point) 3) t)
- (goto-char (line-end-position))
- (insert " "))
- (calc))))))
+ (progn ;;make sure there are two spaces after the account name and go to calc
+ (if (search-backward " " (- (point) 3) t)
+ (goto-char (line-end-position))
+ (insert " "))
+ (calc))))))
(defun ledger-post-prev-xact ()
"Move point to the previous transaction."
diff --git a/lisp/ledger-regex.el b/lisp/ledger-regex.el
index cf10895a..481356ca 100644
--- a/lisp/ledger-regex.el
+++ b/lisp/ledger-regex.el
@@ -27,7 +27,7 @@
(defconst ledger-amount-regex
(concat "\\( \\|\t\\| \t\\)[ \t]*-?"
"\\([A-Z$€£_]+ *\\)?"
- "\\(-?[0-9,]+?\\)"
+ "\\(-?[0-9,\\.]+?\\)"
"\\(.[0-9]+\\)?"
"\\( *[[:word:]€£_\"]+\\)?"
"\\([ \t]*[@={]@?[^\n;]+?\\)?"
@@ -79,8 +79,6 @@
(defconst ledger-account-cleared-regex
"\\(^[ \t]+\\)\\(*\\s-*.*?\\)\\( \\|\t\\|$\\)")
-(defconst ledger-metadata-regex
- "[ \t]+\\(?2:;[ \t]+.+\\)$")
(defmacro ledger-define-regexp (name regex docs &rest args)
"Simplify the creation of a Ledger regex and helper functions."
diff --git a/src/report.h b/src/report.h
index 5897e8f6..d7c80e11 100644
--- a/src/report.h
+++ b/src/report.h
@@ -521,7 +521,7 @@ public:
"%(quoted(code)),"
"%(quoted(payee)),"
"%(quoted(display_account)),"
- "%(quoted(commodity)),"
+ "%(quoted(commodity(scrub(display_amount)))),"
"%(quoted(quantity(scrub(display_amount)))),"
"%(quoted(cleared ? \"*\" : (pending ? \"!\" : \"\"))),"
"%(quoted(join(note | xact.note)))\n");