From 383f17f1146b700f3c152129cf8733c80bc79286 Mon Sep 17 00:00:00 2001 From: 4ourbit <4ourbit@gmail.com> Date: Tue, 31 Dec 2013 02:12:52 +0100 Subject: Context-aware pcomplete rules. Provide completions based on information retrieved with 'ledger-context-at-point'. To support step-by-step completion of transactions some more patterns were added to 'ledger-line-config'. The actual completion rules mostly reuse some of the convenient input commands that are buried in ledger-mode. Using the standard pcomplete termination string (" ") to allow a "context switch" at the end of each completion step. --- lisp/ledger-mode.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lisp/ledger-mode.el') diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el index 28856bd4..209f970e 100644 --- a/lisp/ledger-mode.el +++ b/lisp/ledger-mode.el @@ -145,6 +145,11 @@ Can indent, complete or align depending on context." (defvar ledger-mode-abbrev-table) +(defvar ledger-date-string-today + (format-time-string (or + (cdr (assoc "date-format" ledger-environment-alist)) + ledger-default-date-format))) + (defun ledger-remove-effective-date () "Removes the effective date from a transaction or posting." (interactive) @@ -153,7 +158,7 @@ Can indent, complete or align depending on context." (save-restriction (narrow-to-region (point-at-bol) (point-at-eol)) (beginning-of-line) - (cond ((eq 'xact context) + (cond ((eq 'pmnt-transaction context) (re-search-forward ledger-iso-date-regexp) (when (= (char-after) ?=) (let ((eq-pos (point))) @@ -187,7 +192,7 @@ With a prefix argument, remove the effective date. " (save-restriction (narrow-to-region (point-at-bol) (point-at-eol)) (cond - ((eq 'xact context) + ((eq 'pmnt-transaction context) (beginning-of-line) (re-search-forward ledger-iso-date-regexp) (when (= (char-after) ?=) @@ -320,7 +325,6 @@ With a prefix argument, remove the effective date. " 'ledger-parse-arguments) (set (make-local-variable 'pcomplete-command-completion-function) 'ledger-complete-at-point) - (set (make-local-variable 'pcomplete-termination-string) "") (add-hook 'post-command-hook 'ledger-highlight-xact-under-point nil t) (add-hook 'before-revert-hook 'ledger-occur-remove-all-overlays nil t) -- cgit v1.2.3 From 316b1b7cfefbc3d65994f518df39545ef74f6879 Mon Sep 17 00:00:00 2001 From: 4ourbit <4ourbit@gmail.com> Date: Wed, 1 Jan 2014 22:00:26 +0100 Subject: Plugging ledger pcomplete into completion-at-point. Added documentation on how to use pcomplete transparently via completion-at-point. --- doc/ledger-mode.texi | 5 +++++ lisp/ledger-mode.el | 1 + 2 files changed, 6 insertions(+) (limited to 'lisp/ledger-mode.el') diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi index c8af96cb..e81045c6 100644 --- a/doc/ledger-mode.texi +++ b/doc/ledger-mode.texi @@ -175,6 +175,11 @@ 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/lisp/ledger-mode.el b/lisp/ledger-mode.el index 209f970e..0d683168 100644 --- a/lisp/ledger-mode.el +++ b/lisp/ledger-mode.el @@ -325,6 +325,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 'post-command-hook 'ledger-highlight-xact-under-point nil t) (add-hook 'before-revert-hook 'ledger-occur-remove-all-overlays nil t) -- cgit v1.2.3