]> code.delx.au - gnu-emacs-elpa/blob - company-keywords.el
Bumped version to 0.5.
[gnu-emacs-elpa] / company-keywords.el
1 ;;; company-keywords.el --- a company back-end for programming language keywords
2 ;;
3 ;; Copyright (C) 2009 Nikolaj Schumacher
4 ;;
5 ;; This file is part of company 0.5.
6 ;;
7 ;; This program is free software; you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License
9 ;; as published by the Free Software Foundation; either version 2
10 ;; of the License, or (at your option) any later version.
11 ;;
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 (require 'company)
21 (eval-when-compile (require 'cl))
22
23 (defun company-keywords-upper-lower (&rest lst)
24 ;; Upcase order is different for _.
25 (nconc (sort (mapcar 'upcase lst) 'string<) lst))
26
27 (defvar company-keywords-alist
28 ;; Please contribute corrections or additions.
29 `((c++-mode
30 "asm" "auto" "bool" "break" "case" "catch" "char" "class" "const"
31 "const_cast" "continue" "default" "delete" "do" "double" "dynamic_cast"
32 "else" "enum" "explicit" "export" "extern" "false" "float" "for" "friend"
33 "goto" "if" "inline" "int" "long" "mutable" "namespace" "new"
34 "operator" "private" "protected" "public" "register" "reinterpret_cast"
35 "return" "short" "signed" "sizeof" "static" "static_cast" "struct" "switch"
36 "template" "this" "throw" "true" "try" "typedef" "typeid" "typename"
37 "union" "unsigned" "using" "virtual" "void" "volatile" "wchar_t" "while")
38 (c-mode
39 "auto" "break" "case" "char" "const" "continue" "default" "do"
40 "double" "else" "enum" "extern" "float" "for" "goto" "if" "int" "long"
41 "register" "return" "short" "signed" "sizeof" "static" "struct"
42 "switch" "typedef" "union" "unsigned" "void" "volatile" "while")
43 (csharp-mode
44 "abstract" "add" "alias" "as" "base" "bool" "break" "byte" "case"
45 "catch" "char" "checked" "class" "const" "continue" "decimal" "default"
46 "delegate" "do" "double" "else" "enum" "event" "explicit" "extern"
47 "false" "finally" "fixed" "float" "for" "foreach" "get" "global" "goto"
48 "if" "implicit" "in" "int" "interface" "internal" "is" "lock" "long"
49 "namespace" "new" "null" "object" "operator" "out" "override" "params"
50 "partial" "private" "protected" "public" "readonly" "ref" "remove"
51 "return" "sbyte" "sealed" "set" "short" "sizeof" "stackalloc" "static"
52 "string" "struct" "switch" "this" "throw" "true" "try" "typeof" "uint"
53 "ulong" "unchecked" "unsafe" "ushort" "using" "value" "var" "virtual"
54 "void" "volatile" "where" "while" "yield")
55 (d-mode
56 ;; from http://www.digitalmars.com/d/2.0/lex.html
57 "abstract" "alias" "align" "asm"
58 "assert" "auto" "body" "bool" "break" "byte" "case" "cast" "catch"
59 "cdouble" "cent" "cfloat" "char" "class" "const" "continue" "creal"
60 "dchar" "debug" "default" "delegate" "delete" "deprecated" "do"
61 "double" "else" "enum" "export" "extern" "false" "final" "finally"
62 "float" "for" "foreach" "foreach_reverse" "function" "goto" "idouble"
63 "if" "ifloat" "import" "in" "inout" "int" "interface" "invariant"
64 "ireal" "is" "lazy" "long" "macro" "mixin" "module" "new" "nothrow"
65 "null" "out" "override" "package" "pragma" "private" "protected"
66 "public" "pure" "real" "ref" "return" "scope" "short" "static" "struct"
67 "super" "switch" "synchronized" "template" "this" "throw" "true" "try"
68 "typedef" "typeid" "typeof" "ubyte" "ucent" "uint" "ulong" "union"
69 "unittest" "ushort" "version" "void" "volatile" "wchar" "while" "with")
70 (f90-mode .
71 ;; from f90.el
72 ;; ".AND." ".GE." ".GT." ".LT." ".LE." ".NE." ".OR." ".TRUE." ".FALSE."
73 ,(company-keywords-upper-lower
74 "abs" "abstract" "achar" "acos" "adjustl" "adjustr" "aimag" "aint"
75 "align" "all" "all_prefix" "all_scatter" "all_suffix" "allocatable"
76 "allocate" "allocated" "and" "anint" "any" "any_prefix" "any_scatter"
77 "any_suffix" "asin" "assign" "assignment" "associate" "associated"
78 "asynchronous" "atan" "atan2" "backspace" "bind" "bit_size" "block"
79 "btest" "c_alert" "c_associated" "c_backspace" "c_bool"
80 "c_carriage_return" "c_char" "c_double" "c_double_complex" "c_f_pointer"
81 "c_f_procpointer" "c_float" "c_float_complex" "c_form_feed" "c_funloc"
82 "c_funptr" "c_horizontal_tab" "c_int" "c_int16_t" "c_int32_t" "c_int64_t"
83 "c_int8_t" "c_int_fast16_t" "c_int_fast32_t" "c_int_fast64_t"
84 "c_int_fast8_t" "c_int_least16_t" "c_int_least32_t" "c_int_least64_t"
85 "c_int_least8_t" "c_intmax_t" "c_intptr_t" "c_loc" "c_long"
86 "c_long_double" "c_long_double_complex" "c_long_long" "c_new_line"
87 "c_null_char" "c_null_funptr" "c_null_ptr" "c_ptr" "c_short"
88 "c_signed_char" "c_size_t" "c_vertical_tab" "call" "case" "ceiling"
89 "char" "character" "character_storage_size" "class" "close" "cmplx"
90 "command_argument_count" "common" "complex" "conjg" "contains" "continue"
91 "copy_prefix" "copy_scatter" "copy_suffix" "cos" "cosh" "count"
92 "count_prefix" "count_scatter" "count_suffix" "cpu_time" "cshift"
93 "cycle" "cyclic" "data" "date_and_time" "dble" "deallocate" "deferred"
94 "digits" "dim" "dimension" "distribute" "do" "dot_product" "double"
95 "dprod" "dynamic" "elemental" "else" "elseif" "elsewhere" "end" "enddo"
96 "endfile" "endif" "entry" "enum" "enumerator" "eoshift" "epsilon" "eq"
97 "equivalence" "eqv" "error_unit" "exit" "exp" "exponent" "extends"
98 "extends_type_of" "external" "extrinsic" "false" "file_storage_size"
99 "final" "floor" "flush" "forall" "format" "fraction" "function" "ge"
100 "generic" "get_command" "get_command_argument" "get_environment_variable"
101 "goto" "grade_down" "grade_up" "gt" "hpf_alignment" "hpf_distribution"
102 "hpf_template" "huge" "iachar" "iall" "iall_prefix" "iall_scatter"
103 "iall_suffix" "iand" "iany" "iany_prefix" "iany_scatter" "iany_suffix"
104 "ibclr" "ibits" "ibset" "ichar" "ieee_arithmetic" "ieee_exceptions"
105 "ieee_features" "ieee_get_underflow_mode" "ieee_set_underflow_mode"
106 "ieee_support_underflow_control" "ieor" "if" "ilen" "implicit"
107 "import" "include" "independent" "index" "inherit" "input_unit"
108 "inquire" "int" "integer" "intent" "interface" "intrinsic" "ior"
109 "iostat_end" "iostat_eor" "iparity" "iparity_prefix" "iparity_scatter"
110 "iparity_suffix" "ishft" "ishftc" "iso_c_binding" "iso_fortran_env"
111 "kind" "lbound" "le" "leadz" "len" "len_trim" "lge" "lgt" "lle" "llt"
112 "log" "log10" "logical" "lt" "matmul" "max" "maxexponent" "maxloc"
113 "maxval" "maxval_prefix" "maxval_scatter" "maxval_suffix" "merge"
114 "min" "minexponent" "minloc" "minval" "minval_prefix" "minval_scatter"
115 "minval_suffix" "mod" "module" "modulo" "move_alloc" "mvbits" "namelist"
116 "ne" "nearest" "neqv" "new" "new_line" "nint" "non_intrinsic"
117 "non_overridable" "none" "nopass" "not" "null" "nullify"
118 "number_of_processors" "numeric_storage_size" "only" "onto" "open"
119 "operator" "optional" "or" "output_unit" "pack" "parameter" "parity"
120 "parity_prefix" "parity_scatter" "parity_suffix" "pass" "pause"
121 "pointer" "popcnt" "poppar" "precision" "present" "print" "private"
122 "procedure" "processors" "processors_shape" "product" "product_prefix"
123 "product_scatter" "product_suffix" "program" "protected" "public"
124 "pure" "radix" "random_number" "random_seed" "range" "read" "real"
125 "realign" "recursive" "redistribute" "repeat" "reshape" "result"
126 "return" "rewind" "rrspacing" "same_type_as" "save" "scale" "scan"
127 "select" "selected_char_kind" "selected_int_kind" "selected_real_kind"
128 "sequence" "set_exponent" "shape" "sign" "sin" "sinh" "size" "spacing"
129 "spread" "sqrt" "stop" "subroutine" "sum" "sum_prefix" "sum_scatter"
130 "sum_suffix" "system_clock" "tan" "tanh" "target" "template" "then"
131 "tiny" "transfer" "transpose" "trim" "true" "type" "ubound" "unpack"
132 "use" "value" "verify" "volatile" "wait" "where" "while" "with" "write"))
133 (java-mode
134 "abstract" "assert" "boolean" "break" "byte" "case" "catch" "char" "class"
135 "continue" "default" "do" "double" "else" "enum" "extends" "final"
136 "finally" "float" "for" "if" "implements" "import" "instanceof" "int"
137 "interface" "long" "native" "new" "package" "private" "protected" "public"
138 "return" "short" "static" "strictfp" "super" "switch" "synchronized"
139 "this" "throw" "throws" "transient" "try" "void" "volatile" "while")
140 (javascript-mode
141 "break" "catch" "const" "continue" "delete" "do" "else" "export" "for"
142 "function" "if" "import" "in" "instanceOf" "label" "let" "new" "return"
143 "switch" "this" "throw" "try" "typeof" "var" "void" "while" "with" "yield")
144 (objc-mode
145 "@catch" "@class" "@encode" "@end" "@finally" "@implementation"
146 "@interface" "@private" "@protected" "@protocol" "@public"
147 "@selector" "@synchronized" "@throw" "@try" "alloc" "autorelease"
148 "bycopy" "byref" "in" "inout" "oneway" "out" "release" "retain")
149 (perl-mode
150 ;; from cperl.el
151 "AUTOLOAD" "BEGIN" "CHECK" "CORE" "DESTROY" "END" "INIT" "__END__"
152 "__FILE__" "__LINE__" "abs" "accept" "alarm" "and" "atan2" "bind"
153 "binmode" "bless" "caller" "chdir" "chmod" "chomp" "chop" "chown" "chr"
154 "chroot" "close" "closedir" "cmp" "connect" "continue" "cos"
155 "crypt" "dbmclose" "dbmopen" "defined" "delete" "die" "do" "dump" "each"
156 "else" "elsif" "endgrent" "endhostent" "endnetent" "endprotoent"
157 "endpwent" "endservent" "eof" "eq" "eval" "exec" "exists" "exit" "exp"
158 "fcntl" "fileno" "flock" "for" "foreach" "fork" "format" "formline"
159 "ge" "getc" "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
160 "gethostbyname" "gethostent" "getlogin" "getnetbyaddr" "getnetbyname"
161 "getnetent" "getpeername" "getpgrp" "getppid" "getpriority"
162 "getprotobyname" "getprotobynumber" "getprotoent" "getpwent" "getpwnam"
163 "getpwuid" "getservbyname" "getservbyport" "getservent" "getsockname"
164 "getsockopt" "glob" "gmtime" "goto" "grep" "gt" "hex" "if" "index" "int"
165 "ioctl" "join" "keys" "kill" "last" "lc" "lcfirst" "le" "length"
166 "link" "listen" "local" "localtime" "lock" "log" "lstat" "lt" "map"
167 "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "my" "ne" "next" "no"
168 "not" "oct" "open" "opendir" "or" "ord" "our" "pack" "package" "pipe"
169 "pop" "pos" "print" "printf" "push" "q" "qq" "quotemeta" "qw" "qx"
170 "rand" "read" "readdir" "readline" "readlink" "readpipe" "recv" "redo"
171 "ref" "rename" "require" "reset" "return" "reverse" "rewinddir" "rindex"
172 "rmdir" "scalar" "seek" "seekdir" "select" "semctl" "semget" "semop"
173 "send" "setgrent" "sethostent" "setnetent" "setpgrp" "setpriority"
174 "setprotoent" "setpwent" "setservent" "setsockopt" "shift" "shmctl"
175 "shmget" "shmread" "shmwrite" "shutdown" "sin" "sleep" "socket"
176 "socketpair" "sort" "splice" "split" "sprintf" "sqrt" "srand" "stat"
177 "study" "sub" "substr" "symlink" "syscall" "sysopen" "sysread" "system"
178 "syswrite" "tell" "telldir" "tie" "time" "times" "tr" "truncate" "uc"
179 "ucfirst" "umask" "undef" "unless" "unlink" "unpack" "unshift" "untie"
180 "until" "use" "utime" "values" "vec" "wait" "waitpid"
181 "wantarray" "warn" "while" "write" "x" "xor" "y")
182 (php-mode
183 "__CLASS__" "__DIR__" "__FILE__" "__FUNCTION__" "__LINE__" "__METHOD__"
184 "__NAMESPACE__" "_once" "abstract" "and" "array" "as" "break" "case"
185 "catch" "cfunction" "class" "clone" "const" "continue" "declare"
186 "default" "die" "do" "echo" "else" "elseif" "empty" "enddeclare"
187 "endfor" "endforeach" "endif" "endswitch" "endwhile" "eval" "exception"
188 "exit" "extends" "final" "for" "foreach" "function" "global"
189 "goto" "if" "implements" "include" "instanceof" "interface"
190 "isset" "list" "namespace" "new" "old_function" "or" "php_user_filter"
191 "print" "private" "protected" "public" "require" "require_once" "return"
192 "static" "switch" "this" "throw" "try" "unset" "use" "var" "while" "xor")
193 (python-mode
194 "and" "assert" "break" "class" "continue" "def" "del" "elif" "else"
195 "except" "exec" "finally" "for" "from" "global" "if" "import" "in" "is"
196 "lambda" "not" "or" "pass" "print" "raise" "return" "try" "while" "yield")
197 (ruby-mode
198 "BEGIN" "END" "alias" "and" "begin" "break" "case" "class" "def" "defined"
199 "do" "else" "elsif" "end" "ensure" "false" "for" "if" "in" "module"
200 "next" "nil" "not" "or" "redo" "rescue" "retry" "return" "self" "super"
201 "then" "true" "undef" "unless" "until" "when" "while" "yield")
202 ;; aliases
203 (js2-mode . javascript-mode)
204 (espresso-mode . javascript-mode)
205 (cperl-mode . perl-mode)
206 (jde-mode . java-mode))
207 "*Alist mapping major-modes to sorted keywords for `company-keywords'.")
208
209 ;;;###autoload
210 (defun company-keywords (command &optional arg &rest ignored)
211 "A `company-mode' back-end for programming language keywords."
212 (interactive (list 'interactive))
213 (case command
214 ('interactive (company-begin-backend 'company-))
215 ('prefix (and (assq major-mode company-keywords-alist)
216 (not (company-in-string-or-comment))
217 (or (company-grab-symbol) 'stop)))
218 ('candidates
219 (let ((completion-ignore-case nil)
220 (symbols (cdr (assq major-mode company-keywords-alist))))
221 (all-completions arg (if (consp symbols)
222 symbols
223 (cdr (assq symbols company-keywords-alist))))))
224 ('sorted t)))
225
226 (provide 'company-keywords)
227 ;;; company-keywords.el ends here
228
229