diff options
-rw-r--r-- | lisp/ldg-complete.el | 45 | ||||
-rw-r--r-- | lisp/ldg-mode.el | 6 | ||||
-rw-r--r-- | lisp/ldg-post.el | 8 |
3 files changed, 54 insertions, 5 deletions
diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el index 6607d372..fa0bf87a 100644 --- a/lisp/ldg-complete.el +++ b/lisp/ldg-complete.el @@ -177,6 +177,51 @@ Does not use ledger xact" (if (re-search-backward "\\(\t\\| [ \t]\\)" nil t) (goto-char (match-end 0)))))) + +(defun ledger-pcomplete (&optional interactively) + "Complete rip-off of pcomplete from pcomplete.el, only added +ledger-magic-tab in the previos commads list so that +ledger-magic-tab would cycle properly" + (interactive "p") + (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-backward-char 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 pcomplete-autolist) + (pcomplete-suffix-list pcomplete-suffix-list) + (completions (pcomplete-completions)) + (result (pcomplete-do-complete pcomplete-stub completions))) + (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 'ldg-complete) ;;; ldg-complete.el ends here diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 434d7448..b435ada2 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -44,13 +44,13 @@ (interactive) (remove-overlays)) -(defun ledger-magic-tab () +(defun ledger-magic-tab (&optional interactively) "Decide what to with with <TAB> . Can be pcomplete, or align-posting" - (interactive) + (interactive "p") (if (and (> (point) 1) (looking-back "[:A-Za-z0-9]" 1)) - (pcomplete) + (ledger-pcomplete interactively) (ledger-post-align-postings))) (defvar ledger-mode-abbrev-table) diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index 0de2de7d..bbed297d 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -172,6 +172,9 @@ position, whichever is closer." region alight the posting on the current line." (interactive) (save-excursion + (if (or (not (mark)) + (not (use-region-p))) + (set-mark (point))) (let* ((mark-first (< (mark) (point))) (begin-region (if mark-first (mark) (point))) (end-region (if mark-first (point-marker) (mark-marker))) @@ -180,8 +183,9 @@ region alight the posting on the current line." (goto-char end-region) (setq end-region (copy-marker (line-end-position))) (goto-char begin-region) - (setq begin-region (copy-marker (line-beginning-position))) - (goto-char begin-region) + (goto-char + (setq begin-region + (copy-marker (line-beginning-position)))) (while (or (setq acc-col (ledger-next-account (end-of-line-or-region end-region))) (< (point) (marker-position end-region))) (when acc-col |