From 91861e8fd281d6bc03fd548fda8e84a128122d3f Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Tue, 11 Sep 2012 00:18:17 +0200 Subject: [PATCH] Add ein:ac-chunk-candidates-from-list --- lisp/ein-ac.el | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lisp/ein-ac.el b/lisp/ein-ac.el index 39f4442..72d55e7 100644 --- a/lisp/ein-ac.el +++ b/lisp/ein-ac.el @@ -50,6 +50,36 @@ table) "`ein:dotty-syntax-table' plus \"~\" considered as a word character.") + +;;; Chunk (adapted from auto-complete-chunk.el) + +(defvar ein:ac-chunk-regex + (rx (group-n 1 (| (syntax whitespace) + (syntax open-parenthesis) + (syntax close-parenthesis) + bol)) + (* (+ (| (syntax word) (syntax symbol))) + (syntax punctuation)) + (+ (| (syntax word) (syntax symbol))) + (? (syntax punctuation)) + point) + "A regexp that matches to a \"chunk\" containing words and dots.") + +(defun ein:ac-chunk-beginning () + "Return the position where the chunk begins." + (ignore-errors + (save-excursion + (+ (re-search-backward ein:ac-chunk-regex) (length (match-string 1)))))) + +(defun ein:ac-chunk-candidates-from-list (chunk-list) + "Return matched candidates in CHUNK-LIST." + (let* ((start (ein:ac-chunk-beginning))) + (when start + (loop with prefix = (buffer-substring start (point)) + for cc in chunk-list + when (string-prefix-p prefix cc) + collect cc)))) + ;;; AC Source