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