Path: blob/master/elisp/auto-complete-1.3/auto-complete-config.el
990 views
;;; auto-complete-config.el --- auto-complete additional configuations12;; Copyright (C) 2009, 2010 Tomohiro Matsuyama34;; Author: Tomohiro Matsuyama <[email protected]>5;; Keywords: convenience6;; Version: 1.378;; This program is free software; you can redistribute it and/or modify9;; it under the terms of the GNU General Public License as published by10;; the Free Software Foundation, either version 3 of the License, or11;; (at your option) any later version.1213;; This program is distributed in the hope that it will be useful,14;; but WITHOUT ANY WARRANTY; without even the implied warranty of15;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16;; GNU General Public License for more details.1718;; You should have received a copy of the GNU General Public License19;; along with this program. If not, see <http://www.gnu.org/licenses/>.2021;;; Commentary:2223;;2425;;; Code:2627(eval-when-compile28(require 'cl))2930(require 'auto-complete)31323334;;;; Additional sources3536;; imenu3738(defvar ac-imenu-index nil)3940(ac-clear-variable-every-10-minutes 'ac-imenu-index)4142(defun ac-imenu-candidates ()43(loop with i = 044with stack = (progn45(unless (local-variable-p 'ac-imenu-index)46(make-local-variable 'ac-imenu-index))47(or ac-imenu-index48(setq ac-imenu-index49(ignore-errors50(with-no-warnings51(imenu--make-index-alist))))))52with result53while (and stack (or (not (integerp ac-limit))54(< i ac-limit)))55for node = (pop stack)56if (consp node)57do58(let ((car (car node))59(cdr (cdr node)))60(if (consp cdr)61(mapc (lambda (child)62(push child stack))63cdr)64(when (and (stringp car)65(string-match (concat "^" (regexp-quote ac-prefix)) car))66;; Remove extra characters67(if (string-match "^.*\\(()\\|=\\|<>\\)$" car)68(setq car (substring car 0 (match-beginning 1))))69(push car result)70(incf i))))71finally return (nreverse result)))7273(ac-define-source imenu74'((depends imenu)75(candidates . ac-imenu-candidates)76(symbol . "s")))7778;; gtags7980(defface ac-gtags-candidate-face81'((t (:background "lightgray" :foreground "navy")))82"Face for gtags candidate"83:group 'auto-complete)8485(defface ac-gtags-selection-face86'((t (:background "navy" :foreground "white")))87"Face for the gtags selected candidate."88:group 'auto-complete)8990(defun ac-gtags-candidate ()91(ignore-errors92(split-string (shell-command-to-string (format "global -ci %s" ac-prefix)) "\n")))9394(ac-define-source gtags95'((candidates . ac-gtags-candidate)96(candidate-face . ac-gtags-candidate-face)97(selection-face . ac-gtags-selection-face)98(requires . 3)99(symbol . "s")))100101;; yasnippet102103(defface ac-yasnippet-candidate-face104'((t (:background "sandybrown" :foreground "black")))105"Face for yasnippet candidate."106:group 'auto-complete)107108(defface ac-yasnippet-selection-face109'((t (:background "coral3" :foreground "white")))110"Face for the yasnippet selected candidate."111:group 'auto-complete)112113(defun ac-yasnippet-table-hash (table)114(cond115((fboundp 'yas/snippet-table-hash)116(yas/snippet-table-hash table))117((fboundp 'yas/table-hash)118(yas/table-hash table))))119120(defun ac-yasnippet-table-parent (table)121(cond122((fboundp 'yas/snippet-table-parent)123(yas/snippet-table-parent table))124((fboundp 'yas/table-parent)125(yas/table-parent table))))126127(defun ac-yasnippet-candidate-1 (table)128(with-no-warnings129(let ((hashtab (ac-yasnippet-table-hash table))130(parent (ac-yasnippet-table-parent table))131candidates)132(maphash (lambda (key value)133(push key candidates))134hashtab)135(setq candidates (all-completions ac-prefix (nreverse candidates)))136(if parent137(setq candidates138(append candidates (ac-yasnippet-candidate-1 parent))))139candidates)))140141(defun ac-yasnippet-candidates ()142(with-no-warnings143(if (fboundp 'yas/get-snippet-tables)144;; >0.6.0145(apply 'append (mapcar 'ac-yasnippet-candidate-1 (yas/get-snippet-tables major-mode)))146(let ((table147(if (fboundp 'yas/snippet-table)148;; <0.6.0149(yas/snippet-table major-mode)150;; 0.6.0151(yas/current-snippet-table))))152(if table153(ac-yasnippet-candidate-1 table))))))154155(ac-define-source yasnippet156'((depends yasnippet)157(candidates . ac-yasnippet-candidates)158(action . yas/expand)159(candidate-face . ac-yasnippet-candidate-face)160(selection-face . ac-yasnippet-selection-face)161(symbol . "a")))162163;; semantic164165(defun ac-semantic-candidates (prefix)166(with-no-warnings167(delete "" ; semantic sometimes returns an empty string168(mapcar 'semantic-tag-name169(ignore-errors170(or (semantic-analyze-possible-completions171(semantic-analyze-current-context))172(senator-find-tag-for-completion prefix)))))))173174(ac-define-source semantic175'((available . (or (require 'semantic-ia nil t)176(require 'semantic/ia nil t)))177(candidates . (ac-semantic-candidates ac-prefix))178(prefix . c-dot-ref)179(requires . 0)180(symbol . "m")))181182(ac-define-source semantic-raw183'((available . (or (require 'semantic-ia nil t)184(require 'semantic/ia nil t)))185(candidates . (ac-semantic-candidates ac-prefix))186(symbol . "s")))187188;; eclim189190(defun ac-eclim-candidates ()191(with-no-warnings192(loop for c in (eclim/java-complete)193collect (nth 1 c))))194195(ac-define-source eclim196'((candidates . ac-eclim-candidates)197(prefix . c-dot)198(requires . 0)199(symbol . "f")))200201;; css202203;; Copied from company-css.el204(defconst ac-css-property-alist205;; see http://www.w3.org/TR/CSS21/propidx.html206'(("azimuth" angle "left-side" "far-left" "left" "center-left" "center"207"center-right" "right" "far-right" "right-side" "behind" "leftwards"208"rightwards")209("background" background-color background-image background-repeat210background-attachment background-position)211("background-attachment" "scroll" "fixed")212("background-color" color "transparent")213("background-image" uri "none")214("background-position" percentage length "left" "center" "right" percentage215length "top" "center" "bottom" "left" "center" "right" "top" "center"216"bottom")217("background-repeat" "repeat" "repeat-x" "repeat-y" "no-repeat")218("border" border-width border-style border-color)219("border-bottom" border)220("border-bottom-color" border-color)221("border-bottom-style" border-style)222("border-bottom-width" border-width)223("border-collapse" "collapse" "separate")224("border-color" color "transparent")225("border-left" border)226("border-left-color" border-color)227("border-left-style" border-style)228("border-left-width" border-width)229("border-right" border)230("border-right-color" border-color)231("border-right-style" border-style)232("border-right-width" border-width)233("border-spacing" length length)234("border-style" border-style)235("border-top" border)236("border-top-color" border-color)237("border-top-style" border-style)238("border-top-width" border-width)239("border-width" border-width)240("bottom" length percentage "auto")241("caption-side" "top" "bottom")242("clear" "none" "left" "right" "both")243("clip" shape "auto")244("color" color)245("content" "normal" "none" string uri counter "attr()" "open-quote"246"close-quote" "no-open-quote" "no-close-quote")247("counter-increment" identifier integer "none")248("counter-reset" identifier integer "none")249("cue" cue-before cue-after)250("cue-after" uri "none")251("cue-before" uri "none")252("cursor" uri "*" "auto" "crosshair" "default" "pointer" "move" "e-resize"253"ne-resize" "nw-resize" "n-resize" "se-resize" "sw-resize" "s-resize"254"w-resize" "text" "wait" "help" "progress")255("direction" "ltr" "rtl")256("display" "inline" "block" "list-item" "run-in" "inline-block" "table"257"inline-table" "table-row-group" "table-header-group" "table-footer-group"258"table-row" "table-column-group" "table-column" "table-cell"259"table-caption" "none")260("elevation" angle "below" "level" "above" "higher" "lower")261("empty-cells" "show" "hide")262("float" "left" "right" "none")263("font" font-style font-variant font-weight font-size "/" line-height264font-family "caption" "icon" "menu" "message-box" "small-caption"265"status-bar")266("font-family" family-name generic-family)267("font-size" absolute-size relative-size length percentage)268("font-style" "normal" "italic" "oblique")269("font-variant" "normal" "small-caps")270("font-weight" "normal" "bold" "bolder" "lighter" "100" "200" "300" "400"271"500" "600" "700" "800" "900")272("height" length percentage "auto")273("left" length percentage "auto")274("letter-spacing" "normal" length)275("line-height" "normal" number length percentage)276("list-style" list-style-type list-style-position list-style-image)277("list-style-image" uri "none")278("list-style-position" "inside" "outside")279("list-style-type" "disc" "circle" "square" "decimal" "decimal-leading-zero"280"lower-roman" "upper-roman" "lower-greek" "lower-latin" "upper-latin"281"armenian" "georgian" "lower-alpha" "upper-alpha" "none")282("margin" margin-width)283("margin-bottom" margin-width)284("margin-left" margin-width)285("margin-right" margin-width)286("margin-top" margin-width)287("max-height" length percentage "none")288("max-width" length percentage "none")289("min-height" length percentage)290("min-width" length percentage)291("orphans" integer)292("outline" outline-color outline-style outline-width)293("outline-color" color "invert")294("outline-style" border-style)295("outline-width" border-width)296("overflow" "visible" "hidden" "scroll" "auto")297("padding" padding-width)298("padding-bottom" padding-width)299("padding-left" padding-width)300("padding-right" padding-width)301("padding-top" padding-width)302("page-break-after" "auto" "always" "avoid" "left" "right")303("page-break-before" "auto" "always" "avoid" "left" "right")304("page-break-inside" "avoid" "auto")305("pause" time percentage)306("pause-after" time percentage)307("pause-before" time percentage)308("pitch" frequency "x-low" "low" "medium" "high" "x-high")309("pitch-range" number)310("play-during" uri "mix" "repeat" "auto" "none")311("position" "static" "relative" "absolute" "fixed")312("quotes" string string "none")313("richness" number)314("right" length percentage "auto")315("speak" "normal" "none" "spell-out")316("speak-header" "once" "always")317("speak-numeral" "digits" "continuous")318("speak-punctuation" "code" "none")319("speech-rate" number "x-slow" "slow" "medium" "fast" "x-fast" "faster"320"slower")321("stress" number)322("table-layout" "auto" "fixed")323("text-align" "left" "right" "center" "justify")324("text-decoration" "none" "underline" "overline" "line-through" "blink")325("text-indent" length percentage)326("text-transform" "capitalize" "uppercase" "lowercase" "none")327("top" length percentage "auto")328("unicode-bidi" "normal" "embed" "bidi-override")329("vertical-align" "baseline" "sub" "super" "top" "text-top" "middle"330"bottom" "text-bottom" percentage length)331("visibility" "visible" "hidden" "collapse")332("voice-family" specific-voice generic-voice "*" specific-voice333generic-voice)334("volume" number percentage "silent" "x-soft" "soft" "medium" "loud"335"x-loud")336("white-space" "normal" "pre" "nowrap" "pre-wrap" "pre-line")337("widows" integer)338("width" length percentage "auto")339("word-spacing" "normal" length)340("z-index" "auto" integer))341"A list of CSS properties and their possible values.")342343(defconst ac-css-value-classes344'((absolute-size "xx-small" "x-small" "small" "medium" "large" "x-large"345"xx-large")346(border-style "none" "hidden" "dotted" "dashed" "solid" "double" "groove"347"ridge" "inset" "outset")348(color "aqua" "black" "blue" "fuchsia" "gray" "green" "lime" "maroon" "navy"349"olive" "orange" "purple" "red" "silver" "teal" "white" "yellow"350"rgb")351(counter "counter")352(family-name "Courier" "Helvetica" "Times")353(generic-family "serif" "sans-serif" "cursive" "fantasy" "monospace")354(generic-voice "male" "female" "child")355(margin-width "auto") ;; length percentage356(relative-size "larger" "smaller")357(shape "rect")358(uri "url"))359"A list of CSS property value classes and their contents.")360361(defconst ac-css-pseudo-classes362'("active" "after" "before" "first" "first-child" "first-letter" "first-line"363"focus" "hover" "lang" "left" "link" "right" "visited")364"Identifiers for CSS pseudo-elements and pseudo-classes.")365366(defvar ac-css-property nil367"Current editing property.")368369(defun ac-css-prefix ()370(when (save-excursion (re-search-backward "\\_<\\(.+?\\)\\_>\\s *:.*\\=" nil t))371(setq ac-css-property (match-string 1))372(or (ac-prefix-symbol) (point))))373374(defun ac-css-property-candidates ()375(or (loop with list = (assoc-default ac-css-property ac-css-property-alist)376with value377while (setq value (pop list))378if (symbolp value)379do (setq list380(append list381(or (assoc-default value ac-css-value-classes)382(assoc-default (symbol-name value) ac-css-property-alist))))383else collect value)384ac-css-pseudo-classes))385386(defvar ac-source-css-property387'((candidates . ac-css-property-candidates)388(prefix . ac-css-prefix)389(requires . 0)))390391392393;;;; Not maintained sources394395;; ropemacs396397(defvar ac-ropemacs-loaded nil)398(defun ac-ropemacs-require ()399(with-no-warnings400(unless ac-ropemacs-loaded401(pymacs-load "ropemacs" "rope-")402(if (boundp 'ropemacs-enable-autoimport)403(setq ropemacs-enable-autoimport t))404(setq ac-ropemacs-loaded t))))405406(defun ac-ropemacs-setup ()407(ac-ropemacs-require)408;(setq ac-sources (append (list 'ac-source-ropemacs) ac-sources))409(setq ac-omni-completion-sources '(("\\." ac-source-ropemacs))))410411(defun ac-ropemacs-initialize ()412(autoload 'pymacs-apply "pymacs")413(autoload 'pymacs-call "pymacs")414(autoload 'pymacs-eval "pymacs" nil t)415(autoload 'pymacs-exec "pymacs" nil t)416(autoload 'pymacs-load "pymacs" nil t)417(add-hook 'python-mode-hook 'ac-ropemacs-setup)418t)419420(defvar ac-ropemacs-completions-cache nil)421(defvar ac-source-ropemacs422'((init423. (lambda ()424(setq ac-ropemacs-completions-cache425(mapcar426(lambda (completion)427(concat ac-prefix completion))428(ignore-errors429(rope-completions))))))430(candidates . ac-ropemacs-completions-cache)))431432;; rcodetools433434(defvar ac-source-rcodetools435'((init . (lambda ()436(require 'rcodetools)437(condition-case x438(save-excursion439(rct-exec-and-eval rct-complete-command-name "--completion-emacs-icicles"))440(error) (setq rct-method-completion-table nil))))441(candidates . (lambda ()442(all-completions443ac-prefix444(mapcar445(lambda (completion)446(replace-regexp-in-string "\t.*$" "" (car completion)))447rct-method-completion-table))))))448449450451;;;; Default settings452453(defun ac-common-setup ()454(add-to-list 'ac-sources 'ac-source-filename))455456(defun ac-emacs-lisp-mode-setup ()457(setq ac-sources (append '(ac-source-features ac-source-functions ac-source-yasnippet ac-source-variables ac-source-symbols) ac-sources)))458459(defun ac-cc-mode-setup ()460(setq ac-sources (append '(ac-source-yasnippet ac-source-gtags) ac-sources)))461462(defun ac-ruby-mode-setup ()463(make-local-variable 'ac-ignores)464(add-to-list 'ac-ignores "end"))465466(defun ac-css-mode-setup ()467(setq ac-sources (append '(ac-source-css-property) ac-sources)))468469(defun ac-config-default ()470(setq-default ac-sources '(ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers))471(add-hook 'emacs-lisp-mode-hook 'ac-emacs-lisp-mode-setup)472(add-hook 'c-mode-common-hook 'ac-cc-mode-setup)473(add-hook 'ruby-mode-hook 'ac-ruby-mode-setup)474(add-hook 'css-mode-hook 'ac-css-mode-setup)475(add-hook 'auto-complete-mode-hook 'ac-common-setup)476(global-auto-complete-mode t))477478(provide 'auto-complete-config)479;;; auto-complete-config.el ends here480481482