Implement more efficient completion algorithm. Thanks Thierry! Also remove multi-comment font-locking for performance reasons.

This commit is contained in:
Craig Earls 2013-05-06 11:28:35 -07:00
parent 6b10e2e909
commit fdbae766c1
3 changed files with 38 additions and 61 deletions

View file

@ -69,31 +69,36 @@
;; to the list ;; to the list
(pcomplete-uniqify-list (nreverse payees-list)))) (pcomplete-uniqify-list (nreverse payees-list))))
(defun ledger-find-accounts-in-buffer () (defun ledger-find-accounts-in-buffer ()
"Search through buffer and build tree of accounts. (interactive)
Return tree structure" (let ((origin (point))
(let ((origin (point)) accounts
(account-tree (list t)) (account-tree (list t))
(account-elements nil)) (account-elements nil))
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(while (re-search-forward
ledger-account-or-metadata-regex nil t) (dolist (account
(unless (and (>= origin (match-beginning 0)) (delete-dups
(< origin (match-end 0))) (progn
(while (re-search-forward ledger-account-or-metadata-regex nil t)
(unless (between origin (match-beginning 0) (match-end 0))
(setq accounts (cons (match-string-no-properties 2) accounts))))
accounts)))
(let ((root account-tree))
(setq account-elements (setq account-elements
(split-string (split-string
(match-string-no-properties 2) ":")) account ":"))
(let ((root account-tree)) (while account-elements
(while account-elements (let ((xact (assoc (car account-elements) root)))
(let ((xact (assoc (car account-elements) root))) (if xact
(if xact (setq root (cdr xact))
(setq root (cdr xact)) (setq xact (cons (car account-elements) (list t)))
(setq xact (cons (car account-elements) (list t))) (nconc root (list xact))
(nconc root (list xact)) (setq root (cdr xact))))
(setq root (cdr xact)))) (setq account-elements (cdr account-elements))))))
(setq account-elements (cdr account-elements))))))) account-tree))
account-tree))
(defun ledger-find-metadata-in-buffer () (defun ledger-find-metadata-in-buffer ()
"Search through buffer and build list of metadata. "Search through buffer and build list of metadata.

View file

@ -132,33 +132,6 @@
'ledger-font-other-face)) 'ledger-font-other-face))
"Expressions to highlight in Ledger mode.") "Expressions to highlight in Ledger mode.")
(defun ledger-extend-region-multiline-comment ()
"Adjusts the variables font-lock-beg and font-lock-end if they
fall within a multiline comment. Returns non-nil if an
adjustment is made."
(let (beg end)
;; fix beg
(save-excursion
(goto-char font-lock-beg)
(end-of-line)
(when (re-search-backward ledger-multiline-comment-start-regex nil t)
(setq beg (point))
(re-search-forward ledger-multiline-comment-regex nil t)
(if (and (>= (point) font-lock-beg)
(/= beg font-lock-beg))
(setq font-lock-beg beg)
(setq beg nil))))
;; fix end
(save-excursion
(goto-char font-lock-end)
(end-of-line)
(when (re-search-backward ledger-multiline-comment-start-regex nil t)
(re-search-forward ledger-multiline-comment-regex nil t)
(setq end (point))
(if (> end font-lock-end)
(setq font-lock-end end)
(setq end nil))))
(or beg end)))
(provide 'ldg-fonts) (provide 'ldg-fonts)

View file

@ -124,8 +124,7 @@ Can indent, complete or align depending on context."
(set (make-local-variable 'font-lock-defaults) (set (make-local-variable 'font-lock-defaults)
'(ledger-font-lock-keywords nil t))) '(ledger-font-lock-keywords nil t)))
(setq font-lock-extend-region-functions (setq font-lock-extend-region-functions
(list #'font-lock-extend-region-wholelines (list #'font-lock-extend-region-wholelines))
#'ledger-extend-region-multiline-comment))
(setq font-lock-multiline nil) (setq font-lock-multiline nil)
(set (make-local-variable 'pcomplete-parse-arguments-function) (set (make-local-variable 'pcomplete-parse-arguments-function)