Add completion using auto-complete-mode

This commit is contained in:
Takafumi Arakaki 2012-05-15 23:04:18 +02:00
parent efaaeb98c1
commit 6646b6a963
3 changed files with 71 additions and 0 deletions

52
ein-ac.el Normal file
View file

@ -0,0 +1,52 @@
;;; ein-ac.el --- Auto-complete extension
;; Copyright (C) 2012- Takafumi Arakaki
;; Author: Takafumi Arakaki
;; This file is NOT part of GNU Emacs.
;; ein-ac.el is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; ein-ac.el is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with ein-ac.el. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(eval-when-compile (require 'cl))
(require 'auto-complete)
(defvar ein:ac-dotty-syntax-table
(let ((table (make-syntax-table c-mode-syntax-table)))
(modify-syntax-entry ?. "w" table)
(modify-syntax-entry ?_ "w" table)
table)
"Adapted from `python-dotty-syntax-table'.")
(defun ein:completer-finish-completing-ac (matched-text matches)
"Invoke completion using `auto-complete'.
Only the argument MATCHES is used. MATCHED-TEXT is for
compatibility with `ein:completer-finish-completing-default'."
;; I don't need to check if the point is at right position, as in
;; `ein:completer-finish-completing-default' because `auto-complete'
;; checks it anyway.
(with-syntax-table ein:ac-dotty-syntax-table
(auto-complete
`(((candidates . ',matches)
(symbol . "s"))))))
(provide 'ein-ac)
;;; ein-ac.el ends here

View file

@ -25,11 +25,27 @@
;;; Code:
(require 'ein-utils)
(defun ein:completer-choose ()
(when (require 'auto-complete nil t)
(require 'ein-ac))
(cond
((and (ein:eval-if-bound 'auto-complete-mode)
(fboundp 'ein:completer-finish-completing-ac))
#'ein:completer-finish-completing-ac)
(t
#'ein:completer-finish-completing-default)))
(defun ein:completer-beginning (matched-text)
(save-excursion
(re-search-backward (concat matched-text "\\="))))
(defun ein:completer-finish-completing (matched-text matches)
(let ((completer (ein:completer-choose)))
(funcall completer matched-text matches)))
(defun ein:completer-finish-completing-default (matched-text matches)
(let* ((end (point))
(beg (ein:completer-beginning matched-text))
(word (if (and beg matches)

View file

@ -173,6 +173,9 @@ The value of SYMBOL can be string, alist or function."
`(unless ,place
(setf ,place ,val)))
(defun ein:eval-if-bound (symbol)
(if (boundp symbol) (eval symbol)))
(defun ein:remove-by-index (list indices)
"Remove elements from LIST if its index is in INDICES.
NOTE: This function creates new list."