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