| @ -0,0 +1,4 @@ | |||
| ((nil . ((indent-tabs-mode . nil) | |||
| (fill-column . 80) | |||
| (sentence-end-double-space . t) | |||
| (emacs-lisp-docstring-fill-column . 75)))) | |||
| @ -0,0 +1,2 @@ | |||
| *.elc | |||
| ert.el | |||
| @ -0,0 +1,26 @@ | |||
| # https://github.com/rolandwalker/emacs-travis | |||
| language: emacs-lisp | |||
| env: | |||
| matrix: | |||
| - EMACS=emacs24 | |||
| - EMACS=emacs-snapshot | |||
| install: | |||
| - if [ "$EMACS" = "emacs24" ]; then | |||
| sudo add-apt-repository -y ppa:cassou/emacs && | |||
| sudo apt-get update -qq && | |||
| sudo apt-get install -qq emacs24 emacs24-el; | |||
| fi | |||
| - if [ "$EMACS" = "emacs-snapshot" ]; then | |||
| sudo add-apt-repository -y ppa:ubuntu-elisp/ppa && | |||
| sudo apt-get update -qq && | |||
| sudo apt-get install -qq emacs-snapshot; | |||
| fi | |||
| before_script: | |||
| make downloads | |||
| script: | |||
| make test-batch EMACS=${EMACS} | |||
| @ -0,0 +1,239 @@ | |||
| 2014-04-19 Dmitry Gutov <dgutov@yandex.ru> | |||
| Merge commit '51c140ca9ee32d27cacc7b2b07d4539bf98ae575' from | |||
| company-master | |||
| Conflicts: | |||
| packages/company/company-pysmell.el | |||
| 2014-03-25 Dmitry Gutov <dgutov@yandex.ru> | |||
| Merge commit '4a7995ff69b25990dc520ed9e466dfbcdb7eafc8' from company | |||
| 2014-03-19 Dmitry Gutov <dgutov@yandex.ru> | |||
| Merge commit 'fec7c0b4a8651160c5d759cc6703b2c45852d5bb' | |||
| 2014-03-18 Dmitry Gutov <dgutov@yandex.ru> | |||
| Merge commit '7be4321260f0c73ef4c3cadc646f6bb496650253' from company | |||
| 2014-02-18 Dmitry Gutov <dgutov@yandex.ru> | |||
| Merge commit '119822078ee3024c2d27017d45ef4578fa36040f' from company | |||
| 2014-02-03 Dmitry Gutov <dgutov@yandex.ru> | |||
| Merge commit '67ab56a5469f16652e73667ec3b4f76ff6befee6' from company | |||
| 2014-01-25 Dmitry Gutov <dgutov@yandex.ru> | |||
| Merge commit '8dc8f9525714db66f659a2a51322345068764bd3' from company | |||
| Conflicts: | |||
| packages/company/company-capf.el | |||
| 2014-01-24 Stefan Monnier <monnier@iro.umontreal.ca> | |||
| * company-capf.el (company--capf-data): Don't get confused by lambda | |||
| exps. | |||
| 2014-01-20 Dmitry Gutov <dgutov@yandex.ru> | |||
| Merge commit '2badcc6227a88e1aba288f442af5f4e1ce55d366' from company | |||
| 2014-01-15 Dmitry Gutov <dgutov@yandex.ru> | |||
| Merge commit '8b4d7da0d6aa1e24379fe5ace5bd2705352ea07e' from company | |||
| 2014-01-14 Dmitry Gutov <dgutov@yandex.ru> | |||
| Merge commit '67a96dbbfe645b64291ed62eab6f1eb391a834e0' from company | |||
| Conflicts: | |||
| packages/company/company-elisp.el | |||
| packages/company/company-oddmuse.el | |||
| 2014-01-13 Stefan Monnier <monnier@iro.umontreal.ca> | |||
| * packages/company/company-etags.el: Require `cl' for `case'. | |||
| * packages/company/company-oddmuse.el: Avoid `eval-when' before | |||
| requiring `cl'. | |||
| * packages/company/company-elisp.el (company-elisp): Simplify. | |||
| 2013-10-06 Dmitry Gutov <dgutov@yandex.ru> | |||
| Sync from company/master | |||
| 2013-08-29 Stefan Monnier <monnier@iro.umontreal.ca> | |||
| * packages/company/company-capf.el (company-capf): Add preliminary | |||
| support for doc-buffer, meta, location, and require-match. | |||
| 2013-08-21 Stefan Monnier <monnier@iro.umontreal.ca> | |||
| * packages/company/company-cmake.el: Fix up copyright. Require CL. | |||
| * packages/company/company-template.el | |||
| (company-template--buffer-templates): Declare before first use. | |||
| * packages/company/company-eclim.el (json-array-type): Declare | |||
| json-array-type. | |||
| (company-eclim--candidates): Remove unused var `project-name'. | |||
| 2013-08-21 Stefan Monnier <monnier@iro.umontreal.ca> | |||
| Sync from company/master | |||
| 2013-08-14 Stefan Monnier <monnier@iro.umontreal.ca> | |||
| Mark merge point of company. | |||
| 2013-06-27 Stefan Monnier <monnier@iro.umontreal.ca> | |||
| * GNUmakefile: Rename from Makefile. Add targets for in-place use. | |||
| (all, all-in-place): New targets. | |||
| * admin/archive-contents.el (archive--simple-package-p): Ignore | |||
| autosave files. | |||
| (archive--refresh-pkg-file): New function. | |||
| (archive--write-pkg-file): Print with ' and ` shorthands. | |||
| * packages/company/company-pysmell.el: Don't require pysmell during | |||
| compile. | |||
| * packages/muse/htmlize-hack.el: Don't require htmlize during compile. | |||
| * packages/shen-mode/shen-mode.el (shen-functions): Define during | |||
| compile. | |||
| * smart-operator/smart-operator.el (smart-operator-insert-1): Use | |||
| pcase. | |||
| 2013-05-26 Dmitry Gutov <dgutov@yandex.ru> | |||
| company: Release 0.6.10 | |||
| * Plays nicer with `org-indent-mode`. | |||
| * Works in horizontally scrolled windows. | |||
| Git commit 764d2aa4ba50081adf69408e62d4863905b68b7f | |||
| 2013-05-10 Dmitry Gutov <dgutov@yandex.ru> | |||
| company: Release 0.6.9 | |||
| * `company-capf` respects `:exit-function` completion property. | |||
| * `company-backends`: `prefix` command can return `t` in the cdr. | |||
| * `company-clang-begin-after-member-access`: New option. | |||
| * Mouse click outside the tooltip aborts completion. | |||
| * `company-clang` uses standard input to pass the contents of current | |||
| buffer to | |||
| Clang 2.9+, otherwise saves the buffer and passes the path to the | |||
| file. | |||
| * `company-clang-auto-save` option has been removed. | |||
| * Better interaction with `outline-minor-mode`. | |||
| * `company-dabbrev-code` supports all `prog-mode` derivatives. | |||
| Git commit 4c735454d91f9674da0ecea950504888b1e10ff7 | |||
| 2013-04-27 Stefan Monnier <monnier@iro.umontreal.ca> | |||
| * company.el (company-capf): Add support for `sorted' and | |||
| `post-completion'. | |||
| (company--capf-data): New function. | |||
| (company-backend): Declare before first use. | |||
| (company-require-match-p): Only call company-require-match is needed. | |||
| (company--continue-failed): Don't use backward-delete-char | |||
| non-interactively. | |||
| (company-search-assert-enabled): Demote it, since it comes too late to | |||
| be inlined. | |||
| (company-begin-with): Use a lexical closure, so the code is | |||
| byte-compiled. | |||
| (company--replacement-string, company--create-lines) | |||
| (company-pseudo-tooltip-edit, company-doc-buffer): Silence the | |||
| byte-compiler. | |||
| 2013-04-16 Dmitry Gutov <dgutov@yandex.ru> | |||
| Release 0.6.8 | |||
| * `company-auto-complete` is disabled by default. | |||
| * `company-auto-complete-chars` default value includes fewer syntax | |||
| classes. | |||
| * In expanded function calls, arguments skipped by the user default to | |||
| "argN". | |||
| * `company-eclim` and `company-clang` do not strip argument types from | |||
| fields. | |||
| * `company-clang` expands function calls for all three modes now. | |||
| * `company-clang` supports `c++-mode` by default. | |||
| Git commit 92ac3d0ef663bca26abbda33cc20a02a58b1c328 | |||
| 2013-04-05 Dmitry Gutov <dgutov@yandex.ru> | |||
| company: Release 0.6.7 | |||
| * Two `company-elisp` tweaks. | |||
| Git commit 8dceda389115b397de48becc4b68a64f4dc4bbab | |||
| 2013-04-01 Dmitry Gutov <dgutov@yandex.ru> | |||
| company: Release 0.6.6 | |||
| ## 2013-04-01 (0.6.6) | |||
| * `company-elisp` doesn't offer completions when typing the name and | |||
| the arguments of a new function or macro definition, allowing to | |||
| fall back to other back-ends like `company-dabbrev-code`. | |||
| ## 2013-03-30 (0.6.5) | |||
| * Fixed keybindings when running in a terminal. | |||
| * `company-elisp-show-locals-first`: new customizable variable. | |||
| * `company-elisp` shows more accurate and comprehensive candidates | |||
| list. | |||
| ## 2013-03-26 (0.6.4) | |||
| * `company-eclim` shows valid completions after an opening paren. | |||
| * Expanded template does not get removed until the point leaves it. | |||
| After your input the last argument in a method call expanded by | |||
| `company-eclim`, you can press `<tab>` once more, to jump after the | |||
| closing paren. No other bundled back-ends are affected. | |||
| ## 2013-03-25 (0.6.3) | |||
| * New tooltip face colors used on themes with light background. | |||
| * Pseudo-tooltip stays up-to-date when text is inserted after the | |||
| point. | |||
| * Fixed `company-require-match` mechanics. | |||
| 2013-03-24 Dmitry Gutov <dgutov@yandex.ru> | |||
| company: Release 0.6.2 | |||
| 2013-03-23 Dmitry Gutov <dgutov@yandex.ru> | |||
| company: Release 0.6.1 | |||
| 2013-03-21 Dmitry Gutov <dgutov@yandex.ru> | |||
| company: Remove angle brackets from README | |||
| 2013-03-19 Dmitry Gutov <dgutov@yandex.ru> | |||
| company: Update pkg.el and summary string | |||
| 2013-03-19 Dmitry Gutov <dgutov@yandex.ru> | |||
| company-tests.el: add copyright boilerplate | |||
| 2013-03-19 Dmitry Gutov <dgutov@yandex.ru> | |||
| company-mode: Release 0.6 | |||
| 2011-08-01 Stefan Monnier <monnier@iro.umontreal.ca> | |||
| * company/*.el: Fix case misunderstanding. Use checkdoc. | |||
| * company/company.el (company-capf): First cut at making Company use | |||
| completion-at-point-functions. | |||
| 2011-06-30 Chong Yidong <cyd@stupidchicken.com> | |||
| Remove version numbers in packages/ directory | |||
| @ -0,0 +1,37 @@ | |||
| EMACS=emacs | |||
| CURL=curl --silent | |||
| ERT_URL=http://git.savannah.gnu.org/cgit/emacs.git/plain/lisp/emacs-lisp/ert.el?h=emacs-24.3 | |||
| .PHONY: ert test test-batch | |||
| package: *.el | |||
| @ver=`grep -o "Version: .*" company.el | cut -c 10-`; \ | |||
| tar cjvf company-$$ver.tar.bz2 --mode 644 `git ls-files '*.el' | xargs` | |||
| elpa: *.el | |||
| @version=`grep -o "Version: .*" company.el | cut -c 10-`; \ | |||
| dir=company-$$version; \ | |||
| mkdir -p "$$dir"; \ | |||
| cp `git ls-files '*.el' | xargs` company-$$version; \ | |||
| echo "(define-package \"company\" \"$$version\" \ | |||
| \"Modular in-buffer completion framework\")" \ | |||
| > "$$dir"/company-pkg.el; \ | |||
| tar cvf company-$$version.tar --mode 644 "$$dir" | |||
| clean: | |||
| @rm -rf company-*/ company-*.tar company-*.tar.bz2 *.elc ert.el | |||
| test: | |||
| ${EMACS} -Q -nw -L . -l company-tests.el -l company-elisp-tests.el \ | |||
| --eval "(let (pop-up-windows) (ert t))" | |||
| test-batch: | |||
| ${EMACS} -Q --batch -L . -l company-tests.el -l company-elisp-tests.el \ | |||
| --eval "(ert-run-tests-batch-and-exit '(not (tag interactive)))" | |||
| downloads: | |||
| ${EMACS} -Q --batch -l ert || \ | |||
| ${CURL} ${ERT_URL} > ert.el | |||
| compile: | |||
| ${EMACS} -Q --batch -L . -f batch-byte-compile company.el company-*.el | |||
| @ -0,0 +1,255 @@ | |||
| # History of user-visible changes | |||
| ## 2014-04-19 (0.8.0) | |||
| * `company-capf` is included in `company-backends` in any supported Emacs | |||
| version (>= 24.1). `company-elisp` goes before it if Emacs version is < 24.4. | |||
| * New user option `company-clang-insert-arguments`, by default t. | |||
| * Default value of `company-idle-delay` lowered to `0.5`. | |||
| * New user option `company-tooltip-minimum-width`, by default 0. | |||
| * New function `company-grab-symbol-cons`. | |||
| * `company-clang` fetches completion candidates asynchronously. | |||
| * Added support for asynchronous back-ends (experimental). | |||
| * Support for back-end command `crop` dropped (it was never documented). | |||
| * Support for Emacs 23 dropped. | |||
| * New user option `company-abort-manual-when-too-short`. | |||
| ## 2014-03-25 (0.7.3) | |||
| * New user option `company-etags-ignore-case`. | |||
| ## 2014-03-19 (0.7.2) | |||
| * Support for Emacs 22 officially dropped. | |||
| * `company-clang` supports `indent-tabs-mode` and multibyte chars before point. | |||
| ## 2014-03-18 (0.7.1) | |||
| * Group of back-ends can now contain keyword `:with`, which makes all back-ends | |||
| after it to be skipped for prefix calculation. | |||
| * New function `company-version`. | |||
| * New bundled back-end `company-yasnippet`. | |||
| * Completion candidates returned from grouped back-ends are tagged to remember | |||
| which back-end each came from. | |||
| * New user option `company-tooltip-align-annotations`, off by default. | |||
| * New bundled back-end `company-bbdb`. | |||
| ## 2014-02-18 (0.7) | |||
| * New back-end command, `match`, for non-prefix completion. | |||
| * New user option `company-continue-commands`. The default value aborts | |||
| completion on buffer saving commands. | |||
| * New back-end command, `annotation`, for text displayed inline in the popup | |||
| that's not a part of completion candidate. | |||
| * `company-capf`, `company-clang` and `company-eclim` use `annotation`. | |||
| * `company-preview*` faces inherit from `company-tooltip-selection` and | |||
| `company-tooltip-common-selection` on light themes. | |||
| * New user option `company-transformers`. | |||
| * First transformer, `company-sort-by-occurrence`. | |||
| * New user options controlling `company-dabbrev` and `company-dabbrev-code`. | |||
| ## 2014-01-25 (0.6.14) | |||
| * The tooltip front-end is rendered with scrollbar, controlled by the user | |||
| option `company-tooltip-offset-display`. | |||
| * The tooltip front-end is rendered with margins, controlled by the user option | |||
| `company-tooltip-margin`. | |||
| ## 2014-01-14 (0.6.13) | |||
| * Experimental support for non-prefix completion. | |||
| * Starting with Emacs version 24.4, `company-capf` is included in | |||
| `company-backends` and replaces `company-elisp`. | |||
| * `company-capf` supports completion tables that return non-default boundaries. | |||
| * `company-elisp` is enabled in `inferior-emacs-lisp-mode`. | |||
| ## 2013-09-28 (0.6.12) | |||
| * Default value of `company-begin-commands` changed to `(self-insert-command)`. | |||
| * Futher improvement in `org-indent-mode` compatibility. | |||
| ## 2013-08-18 (0.6.11) | |||
| * `company-template-c-like-templatify` removes all text after closing paren, for | |||
| use in backends that display additional info there. | |||
| * `company-cmake` is now bundled. | |||
| * Better `linum` compatibility in Emacs <= 24.2. | |||
| * `company-global-modes`: New option. | |||
| ## 2013-05-26 (0.6.10) | |||
| * Plays nicer with `org-indent-mode`. | |||
| * Works in horizontally scrolled windows. | |||
| ## 2013-05-10 (0.6.9) | |||
| * `company-capf` respects `:exit-function` completion property. | |||
| * `company-backends`: `prefix` command can return `t` in the cdr. | |||
| * `company-clang-begin-after-member-access`: New option. | |||
| * Mouse click outside the tooltip aborts completion. | |||
| * `company-clang` uses standard input to pass the contents of current buffer to | |||
| Clang 2.9+, otherwise saves the buffer and passes the path to the file. | |||
| * `company-clang-auto-save` option has been removed. | |||
| * Better interaction with `outline-minor-mode`. | |||
| * `company-dabbrev-code` supports all `prog-mode` derivatives. | |||
| ## 2013-04-16 (0.6.8) | |||
| * `company-auto-complete` is disabled by default. | |||
| * `company-auto-complete-chars` default value includes fewer syntax classes. | |||
| * In expanded function calls, arguments skipped by the user default to "argN". | |||
| * `company-eclim` and `company-clang` do not strip argument types from fields. | |||
| * `company-clang` expands function calls for all three modes now. | |||
| * `company-clang` supports `c++-mode` by default. | |||
| ## 2013-04-05 (0.6.7) | |||
| * Two `company-elisp` tweaks. | |||
| ## 2013-04-01 (0.6.6) | |||
| * `company-elisp` doesn't offer completions when typing the name and the | |||
| arguments of a new function or macro definition, allowing to fall back to | |||
| other back-ends like `company-dabbrev-code`. | |||
| ## 2013-03-30 (0.6.5) | |||
| * Fixed keybindings when running in a terminal. | |||
| * `company-elisp-show-locals-first`: new customizable variable. | |||
| * `company-elisp` shows more accurate and comprehensive candidates list. | |||
| ## 2013-03-26 (0.6.4) | |||
| * `company-eclim` shows valid completions after an opening paren. | |||
| * Expanded template does not get removed until the point leaves it. After your | |||
| input the last argument in a method call expanded by `company-eclim`, you can | |||
| press `<tab>` once more, to jump after the closing paren. No other bundled | |||
| back-ends are affected. | |||
| ## 2013-03-25 (0.6.3) | |||
| * New tooltip face colors used on themes with light background. | |||
| * Pseudo-tooltip stays up-to-date when text is inserted after the point. | |||
| * Fixed `company-require-match` mechanics. | |||
| ## 2013-03-24 (0.6.2) | |||
| * `global-company-mode` is now autoloaded. | |||
| ## 2013-03-23 (0.6.1) | |||
| * Documented `init` and `post-completion` back-end commands. | |||
| * `company-eclim` and `company-clang` only expand the template on explicit user | |||
| action (such as `company-complete-{selection,number,mouse}`). | |||
| * `company-template` has some breaking changes. When point is at one of the | |||
| fields, it's displayed at the beginning, not right after it; `<tab>` jumps to | |||
| the next field, `forward-word` and `subword-forward` remappings are removed; | |||
| when you jump to the next field, if the current one hasn't been edited, the | |||
| overlay gets removed but the text remains. | |||
| * `company-eclim` shows method overloads and expands templates for calls. | |||
| * `company-clang-objc-templatify` does not insert spaces after colons anymore. | |||
| * `company-clang` is now only initialized in supported buffers. | |||
| So, no error messages if you don't have Clang until you open a C file. | |||
| * `company-clang` recognizes Clang included in recent Xcode. | |||
| * New commands `company-select-previous-or-abort` and | |||
| `company-select-next-or-abort`, bound to `<up>` and `<down>`. | |||
| ## 2013-03-19 (0.6) | |||
| * Across-the-board bugfixing. | |||
| * `company-pysmell` is not used by default anymore. | |||
| * Loading of `nxml`, `semantic`, `pymacs` and `ropemacs` is now deferred. | |||
| * Candidates from grouped back-ends are merged more conservatively: only | |||
| back-ends that return the same prefix at point are used. | |||
| * `company-clang` now shows meta information, too. | |||
| * Some performance improvements. | |||
| * Fixed two old tooltip annoyances. | |||
| * Instead of `overrriding-terminal-local-map`, we're now using | |||
| `emulation-mode-map-alists` (experimental). This largely means that when the | |||
| completion keymap is active, other minor modes' keymaps are still used, so, | |||
| for example, it's not as easy to accidentally circumvent `paredit-mode` | |||
| when it's enabled. | |||
| * `company-elisp` has seen some improvements. | |||
| * Added `company-capf`: completion adapter using | |||
| `completion-at-point-functions`. (Stefan Monnier) | |||
| * Clang completions now include macros and are case-sensitive. | |||
| * Switching between tag files now works correctly with `company-etags`. | |||
| ## 2010-02-24 (0.5) | |||
| * `company-ropemacs` now provides location and docs. (Fernando H. Silva) | |||
| * Added `company-with-candidate-inserted` macro. | |||
| * Added `company-clang` back-end. | |||
| * Added new mechanism for non-consecutive insertion. | |||
| (So far only used by clang for ObjC.) | |||
| * The semantic back-end now shows meta information for local symbols. | |||
| * Added compatibility for CEDET in Emacs 23.2 and from CVS. (Oleg Andreev) | |||
| ## 2009-05-07 (0.4.3) | |||
| * Added `company-other-backend`. | |||
| * Idle completion no longer interrupts multi-key command input. | |||
| * Added `company-ropemacs` and `company-pysmell` back-ends. | |||
| ## 2009-04-25 (0.4.2) | |||
| * In C modes . and -> now count towards `company-minimum-prefix-length`. | |||
| * Reverted default front-end back to `company-preview-if-just-one-frontend`. | |||
| * The pseudo tooltip will no longer be clipped at the right window edge. | |||
| * Added `company-tooltip-minimum`. | |||
| * Windows compatibility fixes. | |||
| ## 2009-04-19 (0.4.1) | |||
| * Added `global-company-mode`. | |||
| * Performance enhancements. | |||
| * Added `company-eclim` back-end. | |||
| * Added safer workaround for Emacs `posn-col-row` bug. | |||
| ## 2009-04-18 (0.4) | |||
| * Automatic completion is now aborted if the prefix gets too short. | |||
| * Added option `company-dabbrev-time-limit`. | |||
| * `company-backends` now supports merging back-ends. | |||
| * Added back-end `company-dabbrev-code` for generic code. | |||
| * Fixed `company-begin-with`. | |||
| ## 2009-04-15 (0.3.1) | |||
| * Added 'stop prefix to prevent dabbrev from completing inside of symbols. | |||
| * Fixed issues with tabbar-mode and line-spacing. | |||
| * Performance enhancements. | |||
| ## 2009-04-12 (0.3) | |||
| * Added `company-begin-commands` option. | |||
| * Added abbrev, tempo and Xcode back-ends. | |||
| * Back-ends are now interactive. You can start them with M-x backend-name. | |||
| * Added `company-begin-with` for starting company from elisp-code. | |||
| * Added hooks. | |||
| * Added `company-require-match` and `company-auto-complete` options. | |||
| ## 2009-04-05 (0.2.1) | |||
| * Improved Emacs Lisp back-end behavior for local variables. | |||
| * Added `company-elisp-detect-function-context` option. | |||
| * The mouse can now be used for selection. | |||
| ## 2009-03-22 (0.2) | |||
| * Added `company-show-location`. | |||
| * Added etags back-end. | |||
| * Added work-around for end-of-buffer bug. | |||
| * Added `company-filter-candidates`. | |||
| * More local Lisp variables are now included in the candidates. | |||
| ## 2009-03-21 (0.1.5) | |||
| * Fixed elisp documentation buffer always showing the same doc. | |||
| * Added `company-echo-strip-common-frontend`. | |||
| * Added `company-show-numbers` option and M-0 ... M-9 default bindings. | |||
| * Don't hide the echo message if it isn't shown. | |||
| ## 2009-03-20 (0.1) | |||
| * Initial release. | |||
| @ -0,0 +1,4 @@ | |||
| See the [homepage](http://company-mode.github.com/). | |||
| [](http://githalytics.com/company-mode/company-mode) | |||
| [](https://travis-ci.org/company-mode/company-mode) | |||
| @ -0,0 +1,51 @@ | |||
| ;;; company-abbrev.el --- company-mode completion back-end for abbrev | |||
| ;; Copyright (C) 2009-2011 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (require 'abbrev) | |||
| (defun company-abbrev-insert (match) | |||
| "Replace MATCH with the expanded abbrev." | |||
| (expand-abbrev)) | |||
| ;;;###autoload | |||
| (defun company-abbrev (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for abbrev." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-abbrev | |||
| 'company-abbrev-insert)) | |||
| (prefix (company-grab-symbol)) | |||
| (candidates (nconc | |||
| (delete "" (all-completions arg global-abbrev-table)) | |||
| (delete "" (all-completions arg local-abbrev-table)))) | |||
| (meta (abbrev-expansion arg)) | |||
| (require-match t))) | |||
| (provide 'company-abbrev) | |||
| ;;; company-abbrev.el ends here | |||
| @ -0,0 +1,293 @@ | |||
| ;;; company-autoloads.el --- automatically extracted autoloads | |||
| ;; | |||
| ;;; Code: | |||
| (add-to-list 'load-path (or (file-name-directory #$) (car load-path))) | |||
| ;;;### (autoloads nil "company" "company.el" (21400 19789 822176 | |||
| ;;;;;; 187000)) | |||
| ;;; Generated autoloads from company.el | |||
| (autoload 'company-mode "company" "\ | |||
| \"complete anything\"; is an in-buffer completion framework. | |||
| Completion starts automatically, depending on the values | |||
| `company-idle-delay' and `company-minimum-prefix-length'. | |||
| Completion can be controlled with the commands: | |||
| `company-complete-common', `company-complete-selection', `company-complete', | |||
| `company-select-next', `company-select-previous'. If these commands are | |||
| called before `company-idle-delay', completion will also start. | |||
| Completions can be searched with `company-search-candidates' or | |||
| `company-filter-candidates'. These can be used while completion is | |||
| inactive, as well. | |||
| The completion data is retrieved using `company-backends' and displayed | |||
| using `company-frontends'. If you want to start a specific back-end, call | |||
| it interactively or use `company-begin-backend'. | |||
| regular keymap (`company-mode-map'): | |||
| \\{company-mode-map} | |||
| keymap during active completions (`company-active-map'): | |||
| \\{company-active-map} | |||
| \(fn &optional ARG)" t nil) | |||
| (defvar global-company-mode nil "\ | |||
| Non-nil if Global-Company mode is enabled. | |||
| See the command `global-company-mode' for a description of this minor mode. | |||
| Setting this variable directly does not take effect; | |||
| either customize it (see the info node `Easy Customization') | |||
| or call the function `global-company-mode'.") | |||
| (custom-autoload 'global-company-mode "company" nil) | |||
| (autoload 'global-company-mode "company" "\ | |||
| Toggle Company mode in all buffers. | |||
| With prefix ARG, enable Global-Company mode if ARG is positive; | |||
| otherwise, disable it. If called from Lisp, enable the mode if | |||
| ARG is omitted or nil. | |||
| Company mode is enabled in all buffers where | |||
| `company-mode-on' would do it. | |||
| See `company-mode' for more information on Company mode. | |||
| \(fn &optional ARG)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-abbrev" "company-abbrev.el" (21400 | |||
| ;;;;;; 19789 326177 395000)) | |||
| ;;; Generated autoloads from company-abbrev.el | |||
| (autoload 'company-abbrev "company-abbrev" "\ | |||
| `company-mode' completion back-end for abbrev. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-bbdb" "company-bbdb.el" (21400 19789 | |||
| ;;;;;; 854176 109000)) | |||
| ;;; Generated autoloads from company-bbdb.el | |||
| (autoload 'company-bbdb "company-bbdb" "\ | |||
| `company-mode' completion back-end for `bbdb'. | |||
| \(fn COMMAND &optional ARG &rest IGNORE)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-css" "company-css.el" (21400 19789 | |||
| ;;;;;; 366177 298000)) | |||
| ;;; Generated autoloads from company-css.el | |||
| (autoload 'company-css "company-css" "\ | |||
| `company-mode' completion back-end for `css-mode'. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-dabbrev" "company-dabbrev.el" (21400 | |||
| ;;;;;; 19789 410177 191000)) | |||
| ;;; Generated autoloads from company-dabbrev.el | |||
| (autoload 'company-dabbrev "company-dabbrev" "\ | |||
| dabbrev-like `company-mode' completion back-end. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-dabbrev-code" "company-dabbrev-code.el" | |||
| ;;;;;; (21400 19790 74175 574000)) | |||
| ;;; Generated autoloads from company-dabbrev-code.el | |||
| (autoload 'company-dabbrev-code "company-dabbrev-code" "\ | |||
| dabbrev-like `company-mode' back-end for code. | |||
| The back-end looks for all symbols in the current buffer that aren't in | |||
| comments or strings. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-elisp" "company-elisp.el" (21400 19789 | |||
| ;;;;;; 526176 908000)) | |||
| ;;; Generated autoloads from company-elisp.el | |||
| (autoload 'company-elisp "company-elisp" "\ | |||
| `company-mode' completion back-end for Emacs Lisp. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-etags" "company-etags.el" (21400 19789 | |||
| ;;;;;; 114177 912000)) | |||
| ;;; Generated autoloads from company-etags.el | |||
| (autoload 'company-etags "company-etags" "\ | |||
| `company-mode' completion back-end for etags. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-files" "company-files.el" (21400 19789 | |||
| ;;;;;; 570176 801000)) | |||
| ;;; Generated autoloads from company-files.el | |||
| (autoload 'company-files "company-files" "\ | |||
| `company-mode' completion back-end existing file names. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-gtags" "company-gtags.el" (21400 19790 | |||
| ;;;;;; 118175 466000)) | |||
| ;;; Generated autoloads from company-gtags.el | |||
| (autoload 'company-gtags "company-gtags" "\ | |||
| `company-mode' completion back-end for GNU Global. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-ispell" "company-ispell.el" (21400 | |||
| ;;;;;; 19789 78177 999000)) | |||
| ;;; Generated autoloads from company-ispell.el | |||
| (autoload 'company-ispell "company-ispell" "\ | |||
| `company-mode' completion back-end using Ispell. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-keywords" "company-keywords.el" (21400 | |||
| ;;;;;; 19789 158177 804000)) | |||
| ;;; Generated autoloads from company-keywords.el | |||
| (autoload 'company-keywords "company-keywords" "\ | |||
| `company-mode' back-end for programming language keywords. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-nxml" "company-nxml.el" (21400 19789 | |||
| ;;;;;; 190177 726000)) | |||
| ;;; Generated autoloads from company-nxml.el | |||
| (autoload 'company-nxml "company-nxml" "\ | |||
| `company-mode' completion back-end for `nxml-mode'. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-oddmuse" "company-oddmuse.el" (21400 | |||
| ;;;;;; 19789 610176 704000)) | |||
| ;;; Generated autoloads from company-oddmuse.el | |||
| (autoload 'company-oddmuse "company-oddmuse" "\ | |||
| `company-mode' completion back-end for `oddmuse-mode'. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-pysmell" "company-pysmell.el" (21400 | |||
| ;;;;;; 19789 738176 392000)) | |||
| ;;; Generated autoloads from company-pysmell.el | |||
| (autoload 'company-pysmell "company-pysmell" "\ | |||
| `company-mode' completion back-end for pysmell. | |||
| This requires pysmell.el and pymacs.el. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-semantic" "company-semantic.el" (21400 | |||
| ;;;;;; 19790 370174 854000)) | |||
| ;;; Generated autoloads from company-semantic.el | |||
| (autoload 'company-semantic "company-semantic" "\ | |||
| `company-mode' completion back-end using CEDET Semantic. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-tempo" "company-tempo.el" (21400 19789 | |||
| ;;;;;; 930175 924000)) | |||
| ;;; Generated autoloads from company-tempo.el | |||
| (autoload 'company-tempo "company-tempo" "\ | |||
| `company-mode' completion back-end for tempo. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-xcode" "company-xcode.el" (21400 19789 | |||
| ;;;;;; 998175 758000)) | |||
| ;;; Generated autoloads from company-xcode.el | |||
| (autoload 'company-xcode "company-xcode" "\ | |||
| `company-mode' completion back-end for Xcode projects. | |||
| \(fn COMMAND &optional ARG &rest IGNORED)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil "company-yasnippet" "company-yasnippet.el" | |||
| ;;;;;; (21400 19790 242175 165000)) | |||
| ;;; Generated autoloads from company-yasnippet.el | |||
| (autoload 'company-yasnippet "company-yasnippet" "\ | |||
| `company-mode' back-end for `yasnippet'. | |||
| This back-end should be used with care, because as long as there are | |||
| snippets defined for the current major mode, this back-end will always | |||
| shadow back-ends that come after it. Recommended usages: | |||
| * In a buffer-local value of `company-backends', grouped with a back-end or | |||
| several that provide actual text completions. | |||
| (add-hook 'js-mode-hook | |||
| (lambda () | |||
| (set (make-local-variable 'company-backends) | |||
| '((company-dabbrev-code company-yasnippet))))) | |||
| * After keyword `:with', grouped with other back-ends. | |||
| (push '(company-semantic :with company-yasnippet) company-backends) | |||
| * Not in `company-backends', just bound to a key. | |||
| (global-set-key (kbd \"C-c y\") 'company-yasnippet) | |||
| \(fn COMMAND &optional ARG &rest IGNORE)" t nil) | |||
| ;;;*** | |||
| ;;;### (autoloads nil nil ("company-capf.el" "company-clang.el" "company-cmake.el" | |||
| ;;;;;; "company-eclim.el" "company-elisp-tests.el" "company-pkg.el" | |||
| ;;;;;; "company-ropemacs.el" "company-template.el" "company-tests.el") | |||
| ;;;;;; (21400 19790 485375 220000)) | |||
| ;;;*** | |||
| ;; Local Variables: | |||
| ;; version-control: never | |||
| ;; no-byte-compile: t | |||
| ;; no-update-autoloads: t | |||
| ;; End: | |||
| ;;; company-autoloads.el ends here | |||
| @ -0,0 +1,49 @@ | |||
| ;;; company-bbdb.el --- company-mode completion back-end for BBDB in message-mode | |||
| ;; Copyright (C) 2013-2014 Free Software Foundation, Inc. | |||
| ;; Author: Jan Tatarik <jan.tatarik@gmail.com> | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (declare-function bbdb-record-get-field "bbdb") | |||
| (declare-function bbdb-records "bbdb") | |||
| (declare-function bbdb-dwim-mail "bbdb-com") | |||
| (declare-function bbdb-search "bbdb-com") | |||
| ;;;###autoload | |||
| (defun company-bbdb (command &optional arg &rest ignore) | |||
| "`company-mode' completion back-end for `bbdb'." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-bbdb)) | |||
| (prefix (and (eq major-mode 'message-mode) | |||
| (featurep 'bbdb-com) | |||
| (looking-back "^\\(To\\|Cc\\|Bcc\\):.*" | |||
| (line-beginning-position)) | |||
| (company-grab-symbol))) | |||
| (candidates (cl-mapcan (lambda (record) | |||
| (mapcar (lambda (mail) (bbdb-dwim-mail record mail)) | |||
| (bbdb-record-get-field record 'mail))) | |||
| (bbdb-search (bbdb-records) arg nil arg))) | |||
| (sorted t) | |||
| (no-cache t))) | |||
| (provide 'company-bbdb) | |||
| ;;; company-bbdb.el ends here | |||
| @ -0,0 +1,136 @@ | |||
| ;;; company-capf.el --- company-mode completion-at-point-functions back-end -*- lexical-binding: t -*- | |||
| ;; Copyright (C) 2013-2014 Free Software Foundation, Inc. | |||
| ;; Author: Stefan Monnier <monnier@iro.umontreal.ca> | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'cl-lib) | |||
| (defvar company--capf-data nil) | |||
| (make-variable-buffer-local 'company--capf-data) | |||
| (defun company--capf-clear-data (&optional _ignore) | |||
| (setq company--capf-data nil) | |||
| (remove-hook 'company-completion-cancelled-hook 'company--capf-clear-data t) | |||
| (remove-hook 'company-completion-finished-hook 'company--capf-clear-data t)) | |||
| (defun company--capf-data () | |||
| ;; Ignore tags-completion-at-point-function because it subverts company-etags | |||
| ;; in the default value of company-backends, where the latter comes later. | |||
| (cl-letf* (((default-value 'completion-at-point-functions) nil) | |||
| (data (run-hook-wrapped 'completion-at-point-functions | |||
| ;; Ignore misbehaving functions. | |||
| #'completion--capf-wrapper 'optimist))) | |||
| (when (and (consp (cdr data)) (numberp (nth 1 data))) data))) | |||
| (defun company-capf (command &optional arg &rest _args) | |||
| "`company-mode' back-end using `completion-at-point-functions'." | |||
| (interactive (list 'interactive)) | |||
| (pcase command | |||
| (`interactive (company-begin-backend 'company-capf)) | |||
| (`prefix | |||
| (let ((res (company--capf-data))) | |||
| (when res | |||
| (if (> (nth 2 res) (point)) | |||
| 'stop | |||
| (setq company--capf-data res) | |||
| (add-hook 'company-completion-cancelled-hook 'company--capf-clear-data nil t) | |||
| (add-hook 'company-completion-finished-hook 'company--capf-clear-data nil t) | |||
| (buffer-substring-no-properties (nth 1 res) (point)))))) | |||
| (`candidates | |||
| (let ((res company--capf-data)) | |||
| (when res | |||
| (let* ((table (nth 3 res)) | |||
| (pred (plist-get (nthcdr 4 res) :predicate)) | |||
| (meta (completion-metadata | |||
| (buffer-substring (nth 1 res) (nth 2 res)) | |||
| table pred)) | |||
| (sortfun (cdr (assq 'display-sort-function meta))) | |||
| (candidates (completion-all-completions arg table pred (length arg))) | |||
| (last (last candidates)) | |||
| (base-size (and (numberp (cdr last)) (cdr last)))) | |||
| (when base-size | |||
| (setcdr last nil)) | |||
| (when sortfun | |||
| (setq candidates (funcall sortfun candidates))) | |||
| (if (not (zerop (or base-size 0))) | |||
| (let ((before (substring arg 0 base-size))) | |||
| (mapcar (lambda (candidate) | |||
| (concat before candidate)) | |||
| candidates)) | |||
| candidates))))) | |||
| (`sorted | |||
| (let ((res company--capf-data)) | |||
| (when res | |||
| (let ((meta (completion-metadata | |||
| (buffer-substring (nth 1 res) (nth 2 res)) | |||
| (nth 3 res) (plist-get (nthcdr 4 res) :predicate)))) | |||
| (cdr (assq 'display-sort-function meta)))))) | |||
| (`match | |||
| ;; Can't just use 0 when base-size (see above) is non-zero. | |||
| (let ((start (if (get-text-property 0 'font-lock-face arg) | |||
| 0 | |||
| (next-single-property-change 0 'font-lock-face arg)))) | |||
| (when start | |||
| ;; completions-common-part comes first, but we can't just look for this | |||
| ;; value because it can be in a list. | |||
| (or | |||
| (let ((value (get-text-property start 'font-lock-face arg))) | |||
| (text-property-not-all start (length arg) | |||
| 'font-lock-face value arg)) | |||
| (length arg))))) | |||
| (`duplicates t) | |||
| (`no-cache t) ;Not much can be done here, as long as we handle | |||
| ;non-prefix matches. | |||
| (`meta | |||
| (let ((f (plist-get (nthcdr 4 company--capf-data) :company-docsig))) | |||
| (when f (funcall f arg)))) | |||
| (`doc-buffer | |||
| (let ((f (plist-get (nthcdr 4 company--capf-data) :company-doc-buffer))) | |||
| (when f (funcall f arg)))) | |||
| (`location | |||
| (let ((f (plist-get (nthcdr 4 company--capf-data) :company-location))) | |||
| (when f (funcall f arg)))) | |||
| (`annotation | |||
| (save-excursion | |||
| ;; FIXME: `company-begin' sets `company-point' after calling | |||
| ;; `company--begin-new'. We shouldn't rely on `company-point' here, | |||
| ;; better to cache the capf-data value instead. | |||
| (when company-point | |||
| (goto-char company-point)) | |||
| (let ((f (plist-get (nthcdr 4 company--capf-data) :annotation-function))) | |||
| (when f (funcall f arg))))) | |||
| (`require-match | |||
| (plist-get (nthcdr 4 company--capf-data) :company-require-match)) | |||
| (`init nil) ;Don't bother: plenty of other ways to initialize the code. | |||
| (`post-completion | |||
| (let* ((res company--capf-data) | |||
| (exit-function (plist-get (nthcdr 4 res) :exit-function))) | |||
| (if exit-function | |||
| (funcall exit-function arg 'finished)))) | |||
| )) | |||
| (provide 'company-capf) | |||
| ;;; company-capf.el ends here | |||
| @ -0,0 +1,324 @@ | |||
| ;;; company-clang.el --- company-mode completion back-end for Clang -*- lexical-binding: t -*- | |||
| ;; Copyright (C) 2009, 2011, 2013-2014 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'company-template) | |||
| (require 'cl-lib) | |||
| (defgroup company-clang nil | |||
| "Completion back-end for Clang." | |||
| :group 'company) | |||
| (defcustom company-clang-executable | |||
| (executable-find "clang") | |||
| "Location of clang executable." | |||
| :type 'file) | |||
| (defcustom company-clang-begin-after-member-access t | |||
| "When non-nil, automatic completion will start whenever the current | |||
| symbol is preceded by \".\", \"->\" or \"::\", ignoring | |||
| `company-minimum-prefix-length'. | |||
| If `company-begin-commands' is a list, it should include `c-electric-lt-gt' | |||
| and `c-electric-colon', for automatic completion right after \">\" and | |||
| \":\".") | |||
| (defcustom company-clang-arguments nil | |||
| "Additional arguments to pass to clang when completing. | |||
| Prefix files (-include ...) can be selected with `company-clang-set-prefix' | |||
| or automatically through a custom `company-clang-prefix-guesser'." | |||
| :type '(repeat (string :tag "Argument" nil))) | |||
| (defcustom company-clang-prefix-guesser 'company-clang-guess-prefix | |||
| "A function to determine the prefix file for the current buffer." | |||
| :type '(function :tag "Guesser function" nil)) | |||
| (defvar company-clang-modes '(c-mode c++-mode objc-mode) | |||
| "Major modes which clang may complete.") | |||
| (defcustom company-clang-insert-arguments t | |||
| "When non-nil, insert function arguments as a template after completion.") | |||
| ;; prefix ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |||
| (defvar company-clang--prefix nil) | |||
| (defsubst company-clang--guess-pch-file (file) | |||
| (let ((dir (directory-file-name (file-name-directory file)))) | |||
| (when (equal (file-name-nondirectory dir) "Classes") | |||
| (setq dir (file-name-directory dir))) | |||
| (car (directory-files dir t "\\([^.]h\\|[^h]\\).pch\\'" t)))) | |||
| (defsubst company-clang--file-substring (file beg end) | |||
| (with-temp-buffer | |||
| (insert-file-contents-literally file nil beg end) | |||
| (buffer-string))) | |||
| (defun company-clang-guess-prefix () | |||
| "Try to guess the prefix file for the current buffer." | |||
| ;; Prefixes seem to be called .pch. Pre-compiled headers do, too. | |||
| ;; So we look at the magic number to rule them out. | |||
| (let* ((file (company-clang--guess-pch-file buffer-file-name)) | |||
| (magic-number (and file (company-clang--file-substring file 0 4)))) | |||
| (unless (member magic-number '("CPCH" "gpch")) | |||
| file))) | |||
| (defun company-clang-set-prefix (&optional prefix) | |||
| "Use PREFIX as a prefix (-include ...) file for clang completion." | |||
| (interactive (let ((def (funcall company-clang-prefix-guesser))) | |||
| (unless (stringp def) | |||
| (setq def default-directory)) | |||
| (list (read-file-name "Prefix file: " | |||
| (when def (file-name-directory def)) | |||
| def t (when def (file-name-nondirectory def)))))) | |||
| ;; TODO: pre-compile? | |||
| (setq company-clang--prefix (and (stringp prefix) | |||
| (file-regular-p prefix) | |||
| prefix))) | |||
| ;; Clean-up on exit. | |||
| (add-hook 'kill-emacs-hook 'company-clang-set-prefix) | |||
| ;; parsing ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |||
| ;; TODO: Handle Pattern (syntactic hints would be neat). | |||
| ;; Do we ever see OVERLOAD (or OVERRIDE)? | |||
| (defconst company-clang--completion-pattern | |||
| "^COMPLETION: \\_<\\(%s[a-zA-Z0-9_:]*\\)\\(?: : \\(.*\\)$\\)?$") | |||
| (defconst company-clang--error-buffer-name "*clang-error*") | |||
| (defun company-clang--lang-option () | |||
| (if (eq major-mode 'objc-mode) | |||
| (if (string= "m" (file-name-extension buffer-file-name)) | |||
| "objective-c" "objective-c++") | |||
| (substring (symbol-name major-mode) 0 -5))) | |||
| (defun company-clang--parse-output (prefix _objc) | |||
| (goto-char (point-min)) | |||
| (let ((pattern (format company-clang--completion-pattern | |||
| (regexp-quote prefix))) | |||
| (case-fold-search nil) | |||
| lines match) | |||
| (while (re-search-forward pattern nil t) | |||
| (setq match (match-string-no-properties 1)) | |||
| (unless (equal match "Pattern") | |||
| (save-match-data | |||
| (when (string-match ":" match) | |||
| (setq match (substring match 0 (match-beginning 0))))) | |||
| (let ((meta (match-string-no-properties 2))) | |||
| (when (and meta (not (string= match meta))) | |||
| (put-text-property 0 1 'meta | |||
| (company-clang--strip-formatting meta) | |||
| match))) | |||
| (push match lines))) | |||
| lines)) | |||
| (defun company-clang--meta (candidate) | |||
| (get-text-property 0 'meta candidate)) | |||
| (defun company-clang--annotation (candidate) | |||
| (let ((meta (company-clang--meta candidate))) | |||
| (cond | |||
| ((null meta) nil) | |||
| ((string-match ":" meta) | |||
| (substring meta (match-beginning 0))) | |||
| ((string-match "\\((.*)\\'\\)" meta) | |||
| (match-string 1 meta))))) | |||
| (defun company-clang--strip-formatting (text) | |||
| (replace-regexp-in-string | |||
| "#]" " " | |||
| (replace-regexp-in-string "[<{[]#\\|#[>}]" "" text t) | |||
| t)) | |||
| (defun company-clang--handle-error (res args) | |||
| (goto-char (point-min)) | |||
| (let* ((buf (get-buffer-create company-clang--error-buffer-name)) | |||
| (cmd (concat company-clang-executable " " (mapconcat 'identity args " "))) | |||
| (pattern (format company-clang--completion-pattern "")) | |||
| (err (if (re-search-forward pattern nil t) | |||
| (buffer-substring-no-properties (point-min) | |||
| (1- (match-beginning 0))) | |||
| ;; Warn the user more aggressively if no match was found. | |||
| (message "clang failed with error %d:\n%s" res cmd) | |||
| (buffer-string)))) | |||
| (with-current-buffer buf | |||
| (let ((inhibit-read-only t)) | |||
| (erase-buffer) | |||
| (insert (current-time-string) | |||
| (format "\nclang failed with error %d:\n" res) | |||
| cmd "\n\n") | |||
| (insert err) | |||
| (setq buffer-read-only t) | |||
| (goto-char (point-min)))))) | |||
| (defun company-clang--start-process (prefix callback &rest args) | |||
| (let ((objc (derived-mode-p 'objc-mode)) | |||
| (buf (get-buffer-create "*clang-output*"))) | |||
| (with-current-buffer buf (erase-buffer)) | |||
| (if (get-buffer-process buf) | |||
| (funcall callback nil) | |||
| (let ((process (apply #'start-process "company-clang" buf | |||
| company-clang-executable args))) | |||
| (set-process-sentinel | |||
| process | |||
| (lambda (proc status) | |||
| (unless (string-match-p "hangup" status) | |||
| (funcall | |||
| callback | |||
| (let ((res (process-exit-status proc))) | |||
| (with-current-buffer buf | |||
| (unless (eq 0 res) | |||
| (company-clang--handle-error res args)) | |||
| ;; Still try to get any useful input. | |||
| (company-clang--parse-output prefix objc))))))) | |||
| (unless (company-clang--auto-save-p) | |||
| (send-region process (point-min) (point-max)) | |||
| (send-string process "\n") | |||
| (process-send-eof process)))))) | |||
| (defsubst company-clang--build-location (pos) | |||
| (save-excursion | |||
| (goto-char pos) | |||
| (format "%s:%d:%d" | |||
| (if (company-clang--auto-save-p) buffer-file-name "-") | |||
| (line-number-at-pos) | |||
| (1+ (length | |||
| (encode-coding-region | |||
| (line-beginning-position) | |||
| (point) | |||
| 'utf-8 | |||
| t)))))) | |||
| (defsubst company-clang--build-complete-args (pos) | |||
| (append '("-cc1" "-fsyntax-only" "-code-completion-macros") | |||
| (unless (company-clang--auto-save-p) | |||
| (list "-x" (company-clang--lang-option))) | |||
| company-clang-arguments | |||
| (when (stringp company-clang--prefix) | |||
| (list "-include" (expand-file-name company-clang--prefix))) | |||
| '("-code-completion-at") | |||
| (list (company-clang--build-location pos)) | |||
| (list (if (company-clang--auto-save-p) buffer-file-name "-")))) | |||
| (defun company-clang--candidates (prefix callback) | |||
| (and (company-clang--auto-save-p) | |||
| (buffer-modified-p) | |||
| (basic-save-buffer)) | |||
| (when (null company-clang--prefix) | |||
| (company-clang-set-prefix (or (funcall company-clang-prefix-guesser) | |||
| 'none))) | |||
| (apply 'company-clang--start-process | |||
| prefix | |||
| callback | |||
| (company-clang--build-complete-args (- (point) (length prefix))))) | |||
| (defun company-clang--prefix () | |||
| (if company-clang-begin-after-member-access | |||
| (company-grab-symbol-cons "\\.\\|->\\|::" 2) | |||
| (company-grab-symbol))) | |||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |||
| (defconst company-clang-required-version 1.1) | |||
| (defvar company-clang--version nil) | |||
| (defun company-clang--auto-save-p () | |||
| (< company-clang--version 2.9)) | |||
| (defsubst company-clang-version () | |||
| "Return the version of `company-clang-executable'." | |||
| (with-temp-buffer | |||
| (call-process company-clang-executable nil t nil "--version") | |||
| (goto-char (point-min)) | |||
| (if (re-search-forward "clang\\(?: version \\|-\\)\\([0-9.]+\\)" nil t) | |||
| (let ((ver (string-to-number (match-string-no-properties 1)))) | |||
| (if (> ver 100) | |||
| (/ ver 100) | |||
| ver)) | |||
| 0))) | |||
| (defun company-clang-objc-templatify (selector) | |||
| (let* ((end (point-marker)) | |||
| (beg (- (point) (length selector) 1)) | |||
| (templ (company-template-declare-template beg end)) | |||
| (cnt 0)) | |||
| (save-excursion | |||
| (goto-char beg) | |||
| (catch 'stop | |||
| (while (search-forward ":" end t) | |||
| (when (looking-at "([^)]*) ?") | |||
| (delete-region (match-beginning 0) (match-end 0))) | |||
| (company-template-add-field templ (point) (format "arg%d" cnt)) | |||
| (if (< (point) end) | |||
| (insert " ") | |||
| (throw 'stop t)) | |||
| (cl-incf cnt)))) | |||
| (company-template-move-to-first templ))) | |||
| (defun company-clang (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for Clang. | |||
| Clang is a parser for C and ObjC. Clang version 1.1 or newer is required. | |||
| Additional command line arguments can be specified in | |||
| `company-clang-arguments'. Prefix files (-include ...) can be selected | |||
| with `company-clang-set-prefix' or automatically through a custom | |||
| `company-clang-prefix-guesser'. | |||
| With Clang versions before 2.9, we have to save the buffer before | |||
| performing completion. With Clang 2.9 and later, buffer contents are | |||
| passed via standard input." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-clang)) | |||
| (init (when (memq major-mode company-clang-modes) | |||
| (unless company-clang-executable | |||
| (error "Company found no clang executable")) | |||
| (setq company-clang--version (company-clang-version)) | |||
| (when (< company-clang--version company-clang-required-version) | |||
| (error "Company requires clang version 1.1")))) | |||
| (prefix (and (memq major-mode company-clang-modes) | |||
| buffer-file-name | |||
| company-clang-executable | |||
| (not (company-in-string-or-comment)) | |||
| (or (company-clang--prefix) 'stop))) | |||
| (candidates (cons :async | |||
| (lambda (cb) (company-clang--candidates arg cb)))) | |||
| (meta (company-clang--meta arg)) | |||
| (annotation (company-clang--annotation arg)) | |||
| (post-completion (let ((anno (company-clang--annotation arg))) | |||
| (when (and company-clang-insert-arguments anno) | |||
| (insert anno) | |||
| (if (string-match ":" anno) | |||
| (company-clang-objc-templatify anno) | |||
| (company-template-c-like-templatify anno))))))) | |||
| (provide 'company-clang) | |||
| ;;; company-clang.el ends here | |||
| @ -0,0 +1,129 @@ | |||
| ;;; company-cmake.el --- company-mode completion back-end for CMake | |||
| ;; Copyright (C) 2013 Free Software Foundation, Inc. | |||
| ;; Author: Chen Bin <chenbin DOT sh AT gmail> | |||
| ;; Version: 0.1 | |||
| ;; This program 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. | |||
| ;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;; company-cmake offers completions for module names, variable names and | |||
| ;; commands used by CMake. And their descriptions. | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (defgroup company-cmake nil | |||
| "Completion back-end for CMake." | |||
| :group 'company) | |||
| (defcustom company-cmake-executable | |||
| (executable-find "cmake") | |||
| "Location of cmake executable." | |||
| :type 'file) | |||
| (defvar company-cmake-executable-arguments | |||
| '("--help-command-list" | |||
| "--help-module-list" | |||
| "--help-variable-list") | |||
| "The arguments we pass to cmake, separately. | |||
| They affect which types of symbols we get completion candidates for.") | |||
| (defvar company-cmake--completion-pattern | |||
| "^\\(%s[a-zA-Z0-9_]%s\\)$" | |||
| "Regexp to match the candidates.") | |||
| (defvar company-cmake-modes '(cmake-mode) | |||
| "Major modes in which cmake may complete.") | |||
| (defvar company-cmake--meta-command-cache nil | |||
| "Cache for command arguments to retrieve descriptions for the candidates.") | |||
| (defun company-cmake--parse-output (prefix cmd) | |||
| "Analyze the temp buffer and collect lines." | |||
| (goto-char (point-min)) | |||
| (let ((pattern (format company-cmake--completion-pattern | |||
| (regexp-quote prefix) | |||
| (if (zerop (length prefix)) "+" "*"))) | |||
| (case-fold-search nil) | |||
| lines match) | |||
| (while (re-search-forward pattern nil t) | |||
| (setq match (match-string-no-properties 1)) | |||
| (puthash match cmd company-cmake--meta-command-cache) | |||
| (push match lines)) | |||
| lines)) | |||
| (defun company-cmake--candidates (prefix) | |||
| (let ((res 0) | |||
| results | |||
| cmd) | |||
| (setq company-cmake--meta-command-cache (make-hash-table :test 'equal)) | |||
| (dolist (arg company-cmake-executable-arguments) | |||
| (with-temp-buffer | |||
| (setq res (call-process company-cmake-executable nil t nil arg)) | |||
| (unless (eq 0 res) | |||
| (message "cmake executable exited with error=%d" res)) | |||
| (setq cmd (replace-regexp-in-string "-list$" "" arg) ) | |||
| (setq results (nconc results (company-cmake--parse-output prefix cmd))))) | |||
| results)) | |||
| (defun company-cmake--meta (prefix) | |||
| (let ((cmd-opts (gethash prefix company-cmake--meta-command-cache)) | |||
| result) | |||
| (with-temp-buffer | |||
| (call-process company-cmake-executable nil t nil cmd-opts prefix) | |||
| ;; Go to the third line, trim it and return the result. | |||
| ;; Tested with cmake 2.8.9. | |||
| (goto-char (point-min)) | |||
| (forward-line 2) | |||
| (setq result (buffer-substring-no-properties (line-beginning-position) | |||
| (line-end-position))) | |||
| (setq result (replace-regexp-in-string "^[ \t\n\r]+" "" result)) | |||
| result))) | |||
| (defun company-cmake--doc-buffer (prefix) | |||
| (let ((cmd-opts (gethash prefix company-cmake--meta-command-cache))) | |||
| (with-temp-buffer | |||
| (call-process company-cmake-executable nil t nil cmd-opts prefix) | |||
| ;; Go to the third line, trim it and return the doc buffer. | |||
| ;; Tested with cmake 2.8.9. | |||
| (goto-char (point-min)) | |||
| (forward-line 2) | |||
| (company-doc-buffer | |||
| (buffer-substring-no-properties (line-beginning-position) | |||
| (point-max)))))) | |||
| (defun company-cmake (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for CMake. | |||
| CMake is a cross-platform, open-source make system." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-cmake)) | |||
| (init (when (memq major-mode company-cmake-modes) | |||
| (unless company-cmake-executable | |||
| (error "Company found no cmake executable")))) | |||
| (prefix (and (memq major-mode company-cmake-modes) | |||
| (not (company-in-string-or-comment)) | |||
| (company-grab-symbol))) | |||
| (candidates (company-cmake--candidates arg)) | |||
| (meta (company-cmake--meta arg)) | |||
| (doc-buffer (company-cmake--doc-buffer arg)) | |||
| )) | |||
| (provide 'company-cmake) | |||
| ;;; company-cmake.el ends here | |||
| @ -0,0 +1,305 @@ | |||
| ;;; company-css.el --- company-mode completion back-end for css-mode | |||
| ;; Copyright (C) 2009, 2011 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (defconst company-css-property-alist | |||
| ;; see http://www.w3.org/TR/CSS21/propidx.html | |||
| '(("azimuth" angle "left-side" "far-left" "left" "center-left" "center" | |||
| "center-right" "right" "far-right" "right-side" "behind" "leftwards" | |||
| "rightwards") | |||
| ("background" background-color background-image background-repeat | |||
| background-attachment background-position) | |||
| ("background-attachment" "scroll" "fixed") | |||
| ("background-color" color "transparent") | |||
| ("background-image" uri "none") | |||
| ("background-position" percentage length "left" "center" "right" percentage | |||
| length "top" "center" "bottom" "left" "center" "right" "top" "center" | |||
| "bottom") | |||
| ("background-repeat" "repeat" "repeat-x" "repeat-y" "no-repeat") | |||
| ("border" border-width border-style border-color) | |||
| ("border-bottom" border) | |||
| ("border-bottom-color" border-color) | |||
| ("border-bottom-style" border-style) | |||
| ("border-bottom-width" border-width) | |||
| ("border-collapse" "collapse" "separate") | |||
| ("border-color" color "transparent") | |||
| ("border-left" border) | |||
| ("border-left-color" border-color) | |||
| ("border-left-style" border-style) | |||
| ("border-left-width" border-width) | |||
| ("border-right" border) | |||
| ("border-right-color" border-color) | |||
| ("border-right-style" border-style) | |||
| ("border-right-width" border-width) | |||
| ("border-spacing" length length) | |||
| ("border-style" border-style) | |||
| ("border-top" border) | |||
| ("border-top-color" border-color) | |||
| ("border-top-style" border-style) | |||
| ("border-top-width" border-width) | |||
| ("border-width" border-width) | |||
| ("bottom" length percentage "auto") | |||
| ("caption-side" "top" "bottom") | |||
| ("clear" "none" "left" "right" "both") | |||
| ("clip" shape "auto") | |||
| ("color" color) | |||
| ("content" "normal" "none" string uri counter "attr()" "open-quote" | |||
| "close-quote" "no-open-quote" "no-close-quote") | |||
| ("counter-increment" identifier integer "none") | |||
| ("counter-reset" identifier integer "none") | |||
| ("cue" cue-before cue-after) | |||
| ("cue-after" uri "none") | |||
| ("cue-before" uri "none") | |||
| ("cursor" uri "*" "auto" "crosshair" "default" "pointer" "move" "e-resize" | |||
| "ne-resize" "nw-resize" "n-resize" "se-resize" "sw-resize" "s-resize" | |||
| "w-resize" "text" "wait" "help" "progress") | |||
| ("direction" "ltr" "rtl") | |||
| ("display" "inline" "block" "list-item" "run-in" "inline-block" "table" | |||
| "inline-table" "table-row-group" "table-header-group" "table-footer-group" | |||
| "table-row" "table-column-group" "table-column" "table-cell" | |||
| "table-caption" "none") | |||
| ("elevation" angle "below" "level" "above" "higher" "lower") | |||
| ("empty-cells" "show" "hide") | |||
| ("float" "left" "right" "none") | |||
| ("font" font-style font-variant font-weight font-size "/" line-height | |||
| font-family "caption" "icon" "menu" "message-box" "small-caption" | |||
| "status-bar") | |||
| ("font-family" family-name generic-family) | |||
| ("font-size" absolute-size relative-size length percentage) | |||
| ("font-style" "normal" "italic" "oblique") | |||
| ("font-variant" "normal" "small-caps") | |||
| ("font-weight" "normal" "bold" "bolder" "lighter" "100" "200" "300" "400" | |||
| "500" "600" "700" "800" "900") | |||
| ("height" length percentage "auto") | |||
| ("left" length percentage "auto") | |||
| ("letter-spacing" "normal" length) | |||
| ("line-height" "normal" number length percentage) | |||
| ("list-style" list-style-type list-style-position list-style-image) | |||
| ("list-style-image" uri "none") | |||
| ("list-style-position" "inside" "outside") | |||
| ("list-style-type" "disc" "circle" "square" "decimal" "decimal-leading-zero" | |||
| "lower-roman" "upper-roman" "lower-greek" "lower-latin" "upper-latin" | |||
| "armenian" "georgian" "lower-alpha" "upper-alpha" "none") | |||
| ("margin" margin-width) | |||
| ("margin-bottom" margin-width) | |||
| ("margin-left" margin-width) | |||
| ("margin-right" margin-width) | |||
| ("margin-top" margin-width) | |||
| ("max-height" length percentage "none") | |||
| ("max-width" length percentage "none") | |||
| ("min-height" length percentage) | |||
| ("min-width" length percentage) | |||
| ("orphans" integer) | |||
| ("outline" outline-color outline-style outline-width) | |||
| ("outline-color" color "invert") | |||
| ("outline-style" border-style) | |||
| ("outline-width" border-width) | |||
| ("overflow" "visible" "hidden" "scroll" "auto") | |||
| ("padding" padding-width) | |||
| ("padding-bottom" padding-width) | |||
| ("padding-left" padding-width) | |||
| ("padding-right" padding-width) | |||
| ("padding-top" padding-width) | |||
| ("page-break-after" "auto" "always" "avoid" "left" "right") | |||
| ("page-break-before" "auto" "always" "avoid" "left" "right") | |||
| ("page-break-inside" "avoid" "auto") | |||
| ("pause" time percentage) | |||
| ("pause-after" time percentage) | |||
| ("pause-before" time percentage) | |||
| ("pitch" frequency "x-low" "low" "medium" "high" "x-high") | |||
| ("pitch-range" number) | |||
| ("play-during" uri "mix" "repeat" "auto" "none") | |||
| ("position" "static" "relative" "absolute" "fixed") | |||
| ("quotes" string string "none") | |||
| ("richness" number) | |||
| ("right" length percentage "auto") | |||
| ("speak" "normal" "none" "spell-out") | |||
| ("speak-header" "once" "always") | |||
| ("speak-numeral" "digits" "continuous") | |||
| ("speak-punctuation" "code" "none") | |||
| ("speech-rate" number "x-slow" "slow" "medium" "fast" "x-fast" "faster" | |||
| "slower") | |||
| ("stress" number) | |||
| ("table-layout" "auto" "fixed") | |||
| ("text-align" "left" "right" "center" "justify") | |||
| ("text-decoration" "none" "underline" "overline" "line-through" "blink") | |||
| ("text-indent" length percentage) | |||
| ("text-transform" "capitalize" "uppercase" "lowercase" "none") | |||
| ("top" length percentage "auto") | |||
| ("unicode-bidi" "normal" "embed" "bidi-override") | |||
| ("vertical-align" "baseline" "sub" "super" "top" "text-top" "middle" | |||
| "bottom" "text-bottom" percentage length) | |||
| ("visibility" "visible" "hidden" "collapse") | |||
| ("voice-family" specific-voice generic-voice "*" specific-voice | |||
| generic-voice) | |||
| ("volume" number percentage "silent" "x-soft" "soft" "medium" "loud" | |||
| "x-loud") | |||
| ("white-space" "normal" "pre" "nowrap" "pre-wrap" "pre-line") | |||
| ("widows" integer) | |||
| ("width" length percentage "auto") | |||
| ("word-spacing" "normal" length) | |||
| ("z-index" "auto" integer)) | |||
| "A list of CSS properties and their possible values.") | |||
| (defconst company-css-value-classes | |||
| '((absolute-size "xx-small" "x-small" "small" "medium" "large" "x-large" | |||
| "xx-large") | |||
| (border-style "none" "hidden" "dotted" "dashed" "solid" "double" "groove" | |||
| "ridge" "inset" "outset") | |||
| (color "aqua" "black" "blue" "fuchsia" "gray" "green" "lime" "maroon" "navy" | |||
| "olive" "orange" "purple" "red" "silver" "teal" "white" "yellow") | |||
| (counter "counter(,)") | |||
| (family-name "Courier" "Helvetica" "Times") | |||
| (generic-family "serif" "sans-serif" "cursive" "fantasy" "monospace") | |||
| (generic-voice "male" "female" "child") | |||
| (margin-width "auto") ;; length percentage | |||
| (relative-size "larger" "smaller") | |||
| (shape "rect(,,,)") | |||
| (uri "url()")) | |||
| "A list of CSS property value classes and their contents.") | |||
| ;; missing, because not completable | |||
| ;; <angle><frequency><identifier><integer><length><number><padding-width> | |||
| ;; <percentage><specific-voice><string><time><uri> | |||
| (defconst company-css-html-tags | |||
| '("a" "abbr" "acronym" "address" "applet" "area" "b" "base" "basefont" "bdo" | |||
| "big" "blockquote" "body" "br" "button" "caption" "center" "cite" "code" | |||
| "col" "colgroup" "dd" "del" "dfn" "dir" "div" "dl" "dt" "em" "fieldset" | |||
| "font" "form" "frame" "frameset" "h1" "h2" "h3" "h4" "h5" "h6" "head" "hr" | |||
| "html" "i" "iframe" "img" "input" "ins" "isindex" "kbd" "label" "legend" | |||
| "li" "link" "map" "menu" "meta" "noframes" "noscript" "object" "ol" | |||
| "optgroup" "option" "p" "param" "pre" "q" "s" "samp" "script" "select" | |||
| "small" "span" "strike" "strong" "style" "sub" "sup" "table" "tbody" "td" | |||
| "textarea" "tfoot" "th" "thead" "title" "tr" "tt" "u" "ul" "var") | |||
| "A list of HTML tags for use in CSS completion.") | |||
| (defconst company-css-pseudo-classes | |||
| '("active" "after" "before" "first" "first-child" "first-letter" "first-line" | |||
| "focus" "hover" "lang" "left" "link" "right" "visited") | |||
| "Identifiers for CSS pseudo-elements and pseudo-classes.") | |||
| (defconst company-css-property-cache (make-hash-table :size 115 :test 'equal)) | |||
| (defun company-css-property-values (attribute) | |||
| "Access the `company-css-property-alist' cached and flattened." | |||
| (or (gethash attribute company-css-property-cache) | |||
| (let (results) | |||
| (dolist (value (cdr (assoc attribute company-css-property-alist))) | |||
| (if (symbolp value) | |||
| (dolist (child (or (cdr (assoc value company-css-value-classes)) | |||
| (company-css-property-values | |||
| (symbol-name value)))) | |||
| (add-to-list 'results child)) | |||
| (add-to-list 'results value))) | |||
| (setq results (sort results 'string<)) | |||
| (puthash attribute results company-css-property-cache) | |||
| results))) | |||
| ;;; bracket detection | |||
| (defconst company-css-braces-syntax-table | |||
| (let ((table (make-syntax-table))) | |||
| (setf (aref table ?{) '(4 . 125)) | |||
| (setf (aref table ?}) '(5 . 123)) | |||
| table) | |||
| "A syntax table giving { and } paren syntax.") | |||
| (defun company-css-inside-braces-p () | |||
| "Return non-nil, if point is within matched { and }." | |||
| (ignore-errors | |||
| (with-syntax-table company-css-braces-syntax-table | |||
| (let ((parse-sexp-ignore-comments t)) | |||
| (scan-lists (point) -1 1))))) | |||
| ;;; tags | |||
| (defconst company-css-tag-regexp | |||
| (concat "\\(?:\\`\\|}\\)[[:space:]]*" | |||
| ;; multiple | |||
| "\\(?:" | |||
| ;; previous tags: | |||
| "\\(?:#\\|\\_<[[:alpha:]]\\)[[:alnum:]-#]*\\(?:\\[[^]]*\\]\\)?" | |||
| ;; space or selectors | |||
| "\\(?:[[:space:]]+\\|[[:space:]]*[+,>][[:space:]]*\\)" | |||
| "\\)*" | |||
| "\\(\\(?:#\\|\\_<[[:alpha:]]\\)\\(?:[[:alnum:]-#]*\\_>\\)?\\_>\\|\\)" | |||
| "\\=") | |||
| "A regular expression matching CSS tags.") | |||
| ;;; pseudo id | |||
| (defconst company-css-pseudo-regexp | |||
| (concat "\\(?:\\`\\|}\\)[[:space:]]*" | |||
| ;; multiple | |||
| "\\(?:" | |||
| ;; previous tags: | |||
| "\\(?:#\\|\\_<[[:alpha:]]\\)[[:alnum:]-#]*\\(?:\\[[^]]*\\]\\)?" | |||
| ;; space or delimiters | |||
| "\\(?:[[:space:]]+\\|[[:space:]]*[+,>][[:space:]]*\\)" | |||
| "\\)*" | |||
| "\\(?:\\(?:\\#\\|\\_<[[:alpha:]]\\)[[:alnum:]-#]*\\):" | |||
| "\\([[:alpha:]-]+\\_>\\|\\)\\_>\\=") | |||
| "A regular expression matching CSS pseudo classes.") | |||
| ;;; properties | |||
| (defun company-css-grab-property () | |||
| "Return the CSS property before point, if any. | |||
| Returns \"\" if no property found, but feasible at this position." | |||
| (when (company-css-inside-braces-p) | |||
| (company-grab-symbol))) | |||
| ;;; values | |||
| (defconst company-css-property-value-regexp | |||
| "\\_<\\([[:alpha:]-]+\\):\\(?:[^};]*[[:space:]]+\\)?\\([^};]*\\_>\\|\\)\\=" | |||
| "A regular expression matching CSS tags.") | |||
| ;;;###autoload | |||
| (defun company-css (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for `css-mode'." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-css)) | |||
| (prefix (and (derived-mode-p 'css-mode) | |||
| (or (company-grab company-css-tag-regexp 1) | |||
| (company-grab company-css-pseudo-regexp 1) | |||
| (company-grab company-css-property-value-regexp 2) | |||
| (company-css-grab-property)))) | |||
| (candidates | |||
| (cond | |||
| ((company-grab company-css-tag-regexp 1) | |||
| (all-completions arg company-css-html-tags)) | |||
| ((company-grab company-css-pseudo-regexp 1) | |||
| (all-completions arg company-css-pseudo-classes)) | |||
| ((company-grab company-css-property-value-regexp 2) | |||
| (all-completions arg | |||
| (company-css-property-values | |||
| (company-grab company-css-property-value-regexp 1)))) | |||
| ((company-css-grab-property) | |||
| (all-completions arg company-css-property-alist)))) | |||
| (sorted t))) | |||
| (provide 'company-css) | |||
| ;;; company-css.el ends here | |||
| @ -0,0 +1,99 @@ | |||
| ;;; company-dabbrev-code.el --- dabbrev-like company-mode back-end for code | |||
| ;; Copyright (C) 2009, 2011 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'company-dabbrev) | |||
| (require 'cl-lib) | |||
| (defgroup company-dabbrev-code nil | |||
| "dabbrev-like completion back-end for code." | |||
| :group 'company) | |||
| (defcustom company-dabbrev-code-modes | |||
| '(asm-mode batch-file-mode c++-mode c-mode cperl-mode csharp-mode css-mode | |||
| emacs-lisp-mode erlang-mode f90-mode fortran-mode haskell-mode java-mode | |||
| javascript-mode jde-mode js2-mode lisp-mode lua-mode objc-mode perl-mode | |||
| php-mode prog-mode python-mode ruby-mode scheme-mode shell-script-mode) | |||
| "Modes that use `company-dabbrev-code'. | |||
| In all these modes `company-dabbrev-code' will complete only symbols, not text | |||
| in comments or strings. In other modes `company-dabbrev-code' will pass control | |||
| to other back-ends \(e.g. `company-dabbrev'\). | |||
| Value t means complete in all modes." | |||
| :type '(choice (repeat (symbol :tag "Major mode")) | |||
| (const tag "All modes" t))) | |||
| (defcustom company-dabbrev-code-other-buffers t | |||
| "Determines whether `company-dabbrev-code' should search other buffers. | |||
| If `all', search all other buffers. If t, search buffers with the same | |||
| major mode. | |||
| See also `company-dabbrev-code-time-limit'." | |||
| :type '(choice (const :tag "Off" nil) | |||
| (const :tag "Same major mode" t) | |||
| (const :tag "All" all))) | |||
| (defcustom company-dabbrev-code-time-limit .1 | |||
| "Determines how long `company-dabbrev-code' should look for matches." | |||
| :type '(choice (const :tag "Off" nil) | |||
| (number :tag "Seconds"))) | |||
| (defcustom company-dabbrev-code-everywhere nil | |||
| "Non-nil to offer completions in comments and strings." | |||
| :type 'boolean) | |||
| (defcustom company-dabbrev-code-ignore-case nil | |||
| "Non-nil to ignore case in completion candidates." | |||
| :type 'boolean) | |||
| (defsubst company-dabbrev-code--make-regexp (prefix) | |||
| (concat "\\_<" (if (equal prefix "") | |||
| "\\([a-zA-Z]\\|\\s_\\)" | |||
| (regexp-quote prefix)) | |||
| "\\(\\sw\\|\\s_\\)*\\_>")) | |||
| ;;;###autoload | |||
| (defun company-dabbrev-code (command &optional arg &rest ignored) | |||
| "dabbrev-like `company-mode' back-end for code. | |||
| The back-end looks for all symbols in the current buffer that aren't in | |||
| comments or strings." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-dabbrev-code)) | |||
| (prefix (and (or (eq t company-dabbrev-code-modes) | |||
| (apply 'derived-mode-p company-dabbrev-code-modes)) | |||
| (or company-dabbrev-code-everywhere | |||
| (not (company-in-string-or-comment))) | |||
| (or (company-grab-symbol) 'stop))) | |||
| (candidates (let ((case-fold-search company-dabbrev-code-ignore-case)) | |||
| (company-dabbrev--search | |||
| (company-dabbrev-code--make-regexp arg) | |||
| company-dabbrev-code-time-limit | |||
| company-dabbrev-code-other-buffers t))) | |||
| (ignore-case company-dabbrev-code-ignore-case) | |||
| (duplicates t))) | |||
| (provide 'company-dabbrev-code) | |||
| ;;; company-dabbrev-code.el ends here | |||
| @ -0,0 +1,150 @@ | |||
| ;;; company-dabbrev.el --- dabbrev-like company-mode completion back-end | |||
| ;; Copyright (C) 2009, 2011 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (defgroup company-dabbrev nil | |||
| "dabbrev-like completion back-end." | |||
| :group 'company) | |||
| (defcustom company-dabbrev-other-buffers 'all | |||
| "Determines whether `company-dabbrev' should search other buffers. | |||
| If `all', search all other buffers. If t, search buffers with the same | |||
| major mode. | |||
| See also `company-dabbrev-time-limit'." | |||
| :type '(choice (const :tag "Off" nil) | |||
| (const :tag "Same major mode" t) | |||
| (const :tag "All" all))) | |||
| (defcustom company-dabbrev-time-limit .1 | |||
| "Determines how many seconds `company-dabbrev' should look for matches." | |||
| :type '(choice (const :tag "Off" nil) | |||
| (number :tag "Seconds"))) | |||
| (defcustom company-dabbrev-char-regexp "\\sw" | |||
| "A regular expression matching the characters `company-dabbrev' looks for." | |||
| :type 'regexp) | |||
| (defcustom company-dabbrev-ignore-case 'keep-prefix | |||
| "The value of `ignore-case' returned by `company-dabbrev'.") | |||
| (defcustom company-dabbrev-downcase 'case-replace | |||
| "Whether to downcase the returned candidates. | |||
| The value of nil means keep them as-is. | |||
| `case-replace' means use the value of `case-replace'. | |||
| Any other value means downcase. | |||
| If you set this value to nil, you may also want to set | |||
| `company-dabbrev-ignore-case' to any value other than `keep-prefix'.") | |||
| (defcustom company-dabbrev-minimum-length (1+ company-minimum-prefix-length) | |||
| "The minimum length for the string to be included.") | |||
| (defmacro company-dabrev--time-limit-while (test start limit &rest body) | |||
| (declare (indent 3) (debug t)) | |||
| `(let ((company-time-limit-while-counter 0)) | |||
| (catch 'done | |||
| (while ,test | |||
| ,@body | |||
| (and ,limit | |||
| (eq (cl-incf company-time-limit-while-counter) 25) | |||
| (setq company-time-limit-while-counter 0) | |||
| (> (float-time (time-since ,start)) ,limit) | |||
| (throw 'done 'company-time-out)))))) | |||
| (defsubst company-dabbrev--make-regexp (prefix) | |||
| (concat "\\<" (if (equal prefix "") | |||
| company-dabbrev-char-regexp | |||
| (regexp-quote prefix)) | |||
| "\\(" company-dabbrev-char-regexp "\\)*\\>")) | |||
| (defun company-dabbrev--search-buffer (regexp pos symbols start limit | |||
| ignore-comments) | |||
| (save-excursion | |||
| (let (match) | |||
| (goto-char (if pos (1- pos) (point-min))) | |||
| ;; search before pos | |||
| (company-dabrev--time-limit-while (re-search-backward regexp nil t) | |||
| start limit | |||
| (setq match (match-string-no-properties 0)) | |||
| (if (and ignore-comments (company-in-string-or-comment)) | |||
| (re-search-backward "\\s<\\|\\s!\\|\\s\"\\|\\s|" nil t) | |||
| (when (>= (length match) company-dabbrev-minimum-length) | |||
| (push match symbols)))) | |||
| (goto-char (or pos (point-min))) | |||
| ;; search after pos | |||
| (company-dabrev--time-limit-while (re-search-forward regexp nil t) | |||
| start limit | |||
| (setq match (match-string-no-properties 0)) | |||
| (if (and ignore-comments (company-in-string-or-comment)) | |||
| (re-search-forward "\\s>\\|\\s!\\|\\s\"" nil t) | |||
| (when (>= (length match) company-dabbrev-minimum-length) | |||
| (push match symbols)))) | |||
| symbols))) | |||
| (defun company-dabbrev--search (regexp &optional limit other-buffers | |||
| ignore-comments) | |||
| (let* ((start (current-time)) | |||
| (symbols (company-dabbrev--search-buffer regexp (point) nil start limit | |||
| ignore-comments))) | |||
| (when other-buffers | |||
| (cl-dolist (buffer (delq (current-buffer) (buffer-list))) | |||
| (and (or (eq other-buffers 'all) | |||
| (eq (buffer-local-value 'major-mode buffer) major-mode)) | |||
| (with-current-buffer buffer | |||
| (setq symbols | |||
| (company-dabbrev--search-buffer regexp nil symbols start | |||
| limit ignore-comments)))) | |||
| (and limit | |||
| (> (float-time (time-since start)) limit) | |||
| (cl-return)))) | |||
| symbols)) | |||
| ;;;###autoload | |||
| (defun company-dabbrev (command &optional arg &rest ignored) | |||
| "dabbrev-like `company-mode' completion back-end." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-dabbrev)) | |||
| (prefix (company-grab-word)) | |||
| (candidates | |||
| (let ((words (company-dabbrev--search (company-dabbrev--make-regexp arg) | |||
| company-dabbrev-time-limit | |||
| company-dabbrev-other-buffers)) | |||
| (downcase-p (if (eq company-dabbrev-downcase 'case-replace) | |||
| case-replace | |||
| company-dabbrev-downcase))) | |||
| (if downcase-p | |||
| (mapcar 'downcase words) | |||
| words))) | |||
| (ignore-case company-dabbrev-ignore-case) | |||
| (duplicates t))) | |||
| (provide 'company-dabbrev) | |||
| ;;; company-dabbrev.el ends here | |||
| @ -0,0 +1,185 @@ | |||
| ;;; company-eclim.el --- company-mode completion back-end for Eclim | |||
| ;; Copyright (C) 2009, 2011, 2013 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;; Using `emacs-eclim' together with (or instead of) this back-end is | |||
| ;; recommended, as it allows you to use other Eclim features. | |||
| ;; | |||
| ;; The alternative back-end provided by `emacs-eclim' uses `yasnippet' | |||
| ;; instead of `company-template' to expand function calls, and it supports | |||
| ;; some languages other than Java. | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'company-template) | |||
| (require 'cl-lib) | |||
| (defgroup company-eclim nil | |||
| "Completion back-end for Eclim." | |||
| :group 'company) | |||
| (defun company-eclim-executable-find () | |||
| (let (file) | |||
| (cl-dolist (eclipse-root '("/Applications/eclipse" "/usr/lib/eclipse" | |||
| "/usr/local/lib/eclipse")) | |||
| (and (file-exists-p (setq file (expand-file-name "plugins" eclipse-root))) | |||
| (setq file (car (last (directory-files file t "^org.eclim_")))) | |||
| (file-exists-p (setq file (expand-file-name "bin/eclim" file))) | |||
| (cl-return file))))) | |||
| (defcustom company-eclim-executable | |||
| (or (executable-find "eclim") (company-eclim-executable-find)) | |||
| "Location of eclim executable." | |||
| :type 'file) | |||
| (defcustom company-eclim-auto-save t | |||
| "Determines whether to save the buffer when retrieving completions. | |||
| eclim can only complete correctly when the buffer has been saved." | |||
| :type '(choice (const :tag "Off" nil) | |||
| (const :tag "On" t))) | |||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |||
| (defvar company-eclim--project-dir 'unknown) | |||
| (make-variable-buffer-local 'company-eclim--project-dir) | |||
| (defvar company-eclim--project-name nil) | |||
| (make-variable-buffer-local 'company-eclim--project-name) | |||
| (declare-function json-read "json") | |||
| (defvar json-array-type) | |||
| (defun company-eclim--call-process (&rest args) | |||
| (let ((coding-system-for-read 'utf-8) | |||
| res) | |||
| (require 'json) | |||
| (with-temp-buffer | |||
| (if (= 0 (setq res (apply 'call-process company-eclim-executable nil t nil | |||
| "-command" args))) | |||
| (let ((json-array-type 'list)) | |||
| (goto-char (point-min)) | |||
| (unless (eobp) | |||
| (json-read))) | |||
| (message "Company-eclim command failed with error %d:\n%s" res | |||
| (buffer-substring (point-min) (point-max))) | |||
| nil)))) | |||
| (defun company-eclim--project-list () | |||
| (company-eclim--call-process "project_list")) | |||
| (defun company-eclim--project-dir () | |||
| (if (eq company-eclim--project-dir 'unknown) | |||
| (setq company-eclim--project-dir | |||
| (directory-file-name | |||
| (expand-file-name | |||
| (locate-dominating-file buffer-file-name ".project")))) | |||
| company-eclim--project-dir)) | |||
| (defun company-eclim--project-name () | |||
| (or company-eclim--project-name | |||
| (let ((dir (company-eclim--project-dir))) | |||
| (when dir | |||
| (setq company-eclim--project-name | |||
| (cl-loop for project in (company-eclim--project-list) | |||
| when (equal (cdr (assoc 'path project)) dir) | |||
| return (cdr (assoc 'name project)))))))) | |||
| (defun company-eclim--candidates (prefix) | |||
| (interactive "d") | |||
| (let ((project-file (file-relative-name buffer-file-name | |||
| (company-eclim--project-dir))) | |||
| completions) | |||
| (when company-eclim-auto-save | |||
| (when (buffer-modified-p) | |||
| (basic-save-buffer)) | |||
| ;; FIXME: Sometimes this isn't finished when we complete. | |||
| (company-eclim--call-process "java_src_update" | |||
| "-p" (company-eclim--project-name) | |||
| "-f" project-file)) | |||
| (dolist (item (cdr (assoc 'completions | |||
| (company-eclim--call-process | |||
| "java_complete" "-p" (company-eclim--project-name) | |||
| "-f" project-file | |||
| "-o" (number-to-string | |||
| (company-eclim--search-point prefix)) | |||
| "-e" "utf-8" | |||
| "-l" "standard")))) | |||
| (let* ((meta (cdr (assoc 'info item))) | |||
| (completion meta)) | |||
| (when (string-match " ?[(:-]" completion) | |||
| (setq completion (substring completion 0 (match-beginning 0)))) | |||
| (put-text-property 0 1 'meta meta completion) | |||
| (push completion completions))) | |||
| (let ((completion-ignore-case nil)) | |||
| (all-completions prefix completions)))) | |||
| (defun company-eclim--search-point (prefix) | |||
| (if (or (cl-plusp (length prefix)) (eq (char-before) ?.)) | |||
| (1- (point)) | |||
| (point))) | |||
| (defun company-eclim--meta (candidate) | |||
| (get-text-property 0 'meta candidate)) | |||
| (defun company-eclim--annotation (candidate) | |||
| (let ((meta (company-eclim--meta candidate))) | |||
| (when (string-match "\\(([^-]*\\) -" meta) | |||
| (substring meta (match-beginning 1) (match-end 1))))) | |||
| (defun company-eclim--prefix () | |||
| (let ((prefix (company-grab-symbol))) | |||
| (when prefix | |||
| ;; Completion candidates for annotations don't include '@'. | |||
| (when (eq ?@ (string-to-char prefix)) | |||
| (setq prefix (substring prefix 1))) | |||
| prefix))) | |||
| (defun company-eclim (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for Eclim. | |||
| Eclim provides access to Eclipse Java IDE features for other editors. | |||
| Eclim version 1.7.13 or newer (?) is required. | |||
| Completions only work correctly when the buffer has been saved. | |||
| `company-eclim-auto-save' determines whether to do this automatically." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-eclim)) | |||
| (prefix (and (derived-mode-p 'java-mode 'jde-mode) | |||
| buffer-file-name | |||
| company-eclim-executable | |||
| (company-eclim--project-name) | |||
| (not (company-in-string-or-comment)) | |||
| (or (company-eclim--prefix) 'stop))) | |||
| (candidates (company-eclim--candidates arg)) | |||
| (meta (company-eclim--meta arg)) | |||
| ;; because "" doesn't return everything | |||
| (no-cache (equal arg "")) | |||
| (annotation (company-eclim--annotation arg)) | |||
| (post-completion (let ((anno (company-eclim--annotation arg))) | |||
| (when anno | |||
| (insert anno) | |||
| (company-template-c-like-templatify anno)))))) | |||
| (provide 'company-eclim) | |||
| ;;; company-eclim.el ends here | |||
| @ -0,0 +1,193 @@ | |||
| ;;; company-elisp-tests.el --- company-elisp tests | |||
| ;; Copyright (C) 2013-2014 Free Software Foundation, Inc. | |||
| ;; Author: Dmitry Gutov | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company-elisp) | |||
| (defmacro company-elisp-with-buffer (contents &rest body) | |||
| (declare (indent 0)) | |||
| `(with-temp-buffer | |||
| (insert ,contents) | |||
| (setq major-mode 'emacs-lisp-mode) | |||
| (re-search-backward "|") | |||
| (replace-match "") | |||
| (let ((company-elisp-detect-function-context t)) | |||
| ,@body))) | |||
| (ert-deftest company-elisp-candidates-predicate () | |||
| (company-elisp-with-buffer | |||
| "(foo ba|)" | |||
| (should (eq (company-elisp--candidates-predicate "ba") | |||
| 'boundp)) | |||
| (should (eq (let (company-elisp-detect-function-context) | |||
| (company-elisp--candidates-predicate "ba")) | |||
| 'company-elisp--predicate))) | |||
| (company-elisp-with-buffer | |||
| "(foo| )" | |||
| (should (eq (company-elisp--candidates-predicate "foo") | |||
| 'fboundp)) | |||
| (should (eq (let (company-elisp-detect-function-context) | |||
| (company-elisp--candidates-predicate "foo")) | |||
| 'company-elisp--predicate))) | |||
| (company-elisp-with-buffer | |||
| "(foo 'b|)" | |||
| (should (eq (company-elisp--candidates-predicate "b") | |||
| 'company-elisp--predicate)))) | |||
| (ert-deftest company-elisp-candidates-predicate-in-docstring () | |||
| (company-elisp-with-buffer | |||
| "(def foo () \"Doo be doo `ide|" | |||
| (should (eq 'company-elisp--predicate | |||
| (company-elisp--candidates-predicate "ide"))))) | |||
| ;; This one's also an integration test. | |||
| (ert-deftest company-elisp-candidates-recognizes-binding-form () | |||
| (let ((company-elisp-detect-function-context t) | |||
| (obarray [when what whelp]) | |||
| (what 1) | |||
| (whelp 2) | |||
| (wisp 3)) | |||
| (company-elisp-with-buffer | |||
| "(let ((foo 7) (wh| )))" | |||
| (should (equal '("what" "whelp") | |||
| (company-elisp-candidates "wh")))) | |||
| (company-elisp-with-buffer | |||
| "(cond ((null nil) (wh| )))" | |||
| (should (equal '("when") | |||
| (company-elisp-candidates "wh")))))) | |||
| (ert-deftest company-elisp-candidates-predicate-binding-without-value () | |||
| (cl-loop for (text prefix predicate) in '(("(let (foo|" "foo" boundp) | |||
| ("(let (foo (bar|" "bar" boundp) | |||
| ("(let (foo) (bar|" "bar" fboundp)) | |||
| do | |||
| (eval `(company-elisp-with-buffer | |||
| ,text | |||
| (should (eq ',predicate | |||
| (company-elisp--candidates-predicate ,prefix))))))) | |||
| (ert-deftest company-elisp-finds-vars () | |||
| (let ((obarray [boo bar baz backquote]) | |||
| (boo t) | |||
| (bar t) | |||
| (baz t)) | |||
| (should (equal '("bar" "baz") | |||
| (company-elisp--globals "ba" 'boundp))))) | |||
| (ert-deftest company-elisp-finds-functions () | |||
| (let ((obarray [when what whelp]) | |||
| (what t) | |||
| (whelp t)) | |||
| (should (equal '("when") | |||
| (company-elisp--globals "wh" 'fboundp))))) | |||
| (ert-deftest company-elisp-finds-things () | |||
| (let ((obarray [when what whelp]) | |||
| (what t) | |||
| (whelp t)) | |||
| (should (equal '("what" "whelp" "when") | |||
| (sort (company-elisp--globals "wh" 'company-elisp--predicate) | |||
| 'string<))))) | |||
| (ert-deftest company-elisp-locals-vars () | |||
| (company-elisp-with-buffer | |||
| "(let ((foo 5) (bar 6)) | |||
| (cl-labels ((borg ())) | |||
| (lambda (boo baz) | |||
| b|)))" | |||
| (should (equal '("bar" "baz" "boo") | |||
| (company-elisp--locals "b" nil))))) | |||
| (ert-deftest company-elisp-locals-single-var () | |||
| (company-elisp-with-buffer | |||
| "(dotimes (itk 100) | |||
| (dolist (item items) | |||
| it|))" | |||
| (should (equal '("itk" "item") | |||
| (company-elisp--locals "it" nil))))) | |||
| (ert-deftest company-elisp-locals-funs () | |||
| (company-elisp-with-buffer | |||
| "(cl-labels ((foo ()) | |||
| (fee ())) | |||
| (let ((fun 4)) | |||
| (f| )))" | |||
| (should (equal '("fee" "foo") | |||
| (sort (company-elisp--locals "f" t) 'string<))))) | |||
| (ert-deftest company-elisp-locals-skips-current-varlist () | |||
| (company-elisp-with-buffer | |||
| "(let ((foo 1) | |||
| (f| )))" | |||
| (should (null (company-elisp--locals "f" nil))))) | |||
| (ert-deftest company-elisp-show-locals-first () | |||
| (company-elisp-with-buffer | |||
| "(let ((floo 1) | |||
| (flop 2) | |||
| (flee 3)) | |||
| fl|)" | |||
| (let ((obarray [float-pi])) | |||
| (let (company-elisp-show-locals-first) | |||
| (should (eq nil (company-elisp 'sorted)))) | |||
| (let ((company-elisp-show-locals-first t)) | |||
| (should (eq t (company-elisp 'sorted))) | |||
| (should (equal '("flee" "floo" "flop" "float-pi") | |||
| (company-elisp-candidates "fl"))))))) | |||
| (ert-deftest company-elisp-candidates-no-duplicates () | |||
| (company-elisp-with-buffer | |||
| "(let ((float-pi 4)) | |||
| f|)" | |||
| (let ((obarray [float-pi]) | |||
| (company-elisp-show-locals-first t)) | |||
| (should (equal '("float-pi") (company-elisp-candidates "f")))))) | |||
| (ert-deftest company-elisp-shouldnt-complete-defun-name () | |||
| (company-elisp-with-buffer | |||
| "(defun foob|)" | |||
| (should (null (company-elisp 'prefix))))) | |||
| (ert-deftest company-elisp-should-complete-def-call () | |||
| (company-elisp-with-buffer | |||
| "(defu|" | |||
| (should (equal "defu" (company-elisp 'prefix))))) | |||
| (ert-deftest company-elisp-should-complete-in-defvar () | |||
| ;; It will also complete the var name, at least for now. | |||
| (company-elisp-with-buffer | |||
| "(defvar abc de|" | |||
| (should (equal "de" (company-elisp 'prefix))))) | |||
| (ert-deftest company-elisp-shouldnt-complete-in-defun-arglist () | |||
| (company-elisp-with-buffer | |||
| "(defsubst foobar (ba|" | |||
| (should (null (company-elisp 'prefix))))) | |||
| (ert-deftest company-elisp-prefix-in-defun-body () | |||
| (company-elisp-with-buffer | |||
| "(defun foob ()|)" | |||
| (should (equal "" (company-elisp 'prefix))))) | |||
| @ -0,0 +1,225 @@ | |||
| ;;; company-elisp.el --- company-mode completion back-end for Emacs Lisp -*- lexical-binding: t -*- | |||
| ;; Copyright (C) 2009, 2011-2013 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (require 'help-mode) | |||
| (require 'find-func) | |||
| (defgroup company-elisp nil | |||
| "Completion back-end for Emacs Lisp." | |||
| :group 'company) | |||
| (defcustom company-elisp-detect-function-context t | |||
| "If enabled, offer Lisp functions only in appropriate contexts. | |||
| Functions are offered for completion only after ' and \(." | |||
| :type '(choice (const :tag "Off" nil) | |||
| (const :tag "On" t))) | |||
| (defcustom company-elisp-show-locals-first t | |||
| "If enabled, locally bound variables and functions are displayed | |||
| first in the candidates list." | |||
| :type '(choice (const :tag "Off" nil) | |||
| (const :tag "On" t))) | |||
| (defun company-elisp--prefix () | |||
| (let ((prefix (company-grab-symbol))) | |||
| (if prefix | |||
| (when (if (company-in-string-or-comment) | |||
| (= (char-before (- (point) (length prefix))) ?`) | |||
| (company-elisp--should-complete)) | |||
| prefix) | |||
| 'stop))) | |||
| (defun company-elisp--predicate (symbol) | |||
| (or (boundp symbol) | |||
| (fboundp symbol) | |||
| (facep symbol) | |||
| (featurep symbol))) | |||
| (defun company-elisp--fns-regexp (&rest names) | |||
| (concat "\\_<\\(?:cl-\\)?" (regexp-opt names) "\\*?\\_>")) | |||
| (defvar company-elisp-parse-limit 30) | |||
| (defvar company-elisp-parse-depth 100) | |||
| (defvar company-elisp-defun-names '("defun" "defmacro" "defsubst")) | |||
| (defvar company-elisp-var-binding-regexp | |||
| (apply #'company-elisp--fns-regexp "let" "lambda" "lexical-let" | |||
| company-elisp-defun-names) | |||
| "Regular expression matching head of a multiple variable bindings form.") | |||
| (defvar company-elisp-var-binding-regexp-1 | |||
| (company-elisp--fns-regexp "dolist" "dotimes") | |||
| "Regular expression matching head of a form with one variable binding.") | |||
| (defvar company-elisp-fun-binding-regexp | |||
| (company-elisp--fns-regexp "flet" "labels") | |||
| "Regular expression matching head of a function bindings form.") | |||
| (defvar company-elisp-defuns-regexp | |||
| (concat "([ \t\n]*" | |||
| (apply #'company-elisp--fns-regexp company-elisp-defun-names))) | |||
| (defun company-elisp--should-complete () | |||
| (let ((start (point)) | |||
| (depth (car (syntax-ppss)))) | |||
| (not | |||
| (when (> depth 0) | |||
| (save-excursion | |||
| (up-list (- depth)) | |||
| (when (looking-at company-elisp-defuns-regexp) | |||
| (forward-char) | |||
| (forward-sexp 1) | |||
| (unless (= (point) start) | |||
| (condition-case nil | |||
| (let ((args-end (scan-sexps (point) 2))) | |||
| (or (null args-end) | |||
| (> args-end start))) | |||
| (scan-error | |||
| t))))))))) | |||
| (defun company-elisp--locals (prefix functions-p) | |||
| (let ((regexp (concat "[ \t\n]*\\(\\_<" (regexp-quote prefix) | |||
| "\\(?:\\sw\\|\\s_\\)*\\_>\\)")) | |||
| (pos (point)) | |||
| res) | |||
| (condition-case nil | |||
| (save-excursion | |||
| (dotimes (_ company-elisp-parse-depth) | |||
| (up-list -1) | |||
| (save-excursion | |||
| (when (eq (char-after) ?\() | |||
| (forward-char 1) | |||
| (when (ignore-errors | |||
| (save-excursion (forward-list) | |||
| (<= (point) pos))) | |||
| (skip-chars-forward " \t\n") | |||
| (cond | |||
| ((looking-at (if functions-p | |||
| company-elisp-fun-binding-regexp | |||
| company-elisp-var-binding-regexp)) | |||
| (down-list 1) | |||
| (condition-case nil | |||
| (dotimes (_ company-elisp-parse-limit) | |||
| (save-excursion | |||
| (when (looking-at "[ \t\n]*(") | |||
| (down-list 1)) | |||
| (when (looking-at regexp) | |||
| (cl-pushnew (match-string-no-properties 1) res))) | |||
| (forward-sexp)) | |||
| (scan-error nil))) | |||
| ((unless functions-p | |||
| (looking-at company-elisp-var-binding-regexp-1)) | |||
| (down-list 1) | |||
| (when (looking-at regexp) | |||
| (cl-pushnew (match-string-no-properties 1) res))))))))) | |||
| (scan-error nil)) | |||
| res)) | |||
| (defun company-elisp-candidates (prefix) | |||
| (let* ((predicate (company-elisp--candidates-predicate prefix)) | |||
| (locals (company-elisp--locals prefix (eq predicate 'fboundp))) | |||
| (globals (company-elisp--globals prefix predicate)) | |||
| (locals (cl-loop for local in locals | |||
| when (not (member local globals)) | |||
| collect local))) | |||
| (if company-elisp-show-locals-first | |||
| (append (sort locals 'string<) | |||
| (sort globals 'string<)) | |||
| (append locals globals)))) | |||
| (defun company-elisp--globals (prefix predicate) | |||
| (all-completions prefix obarray predicate)) | |||
| (defun company-elisp--candidates-predicate (prefix) | |||
| (let* ((completion-ignore-case nil) | |||
| (beg (- (point) (length prefix))) | |||
| (before (char-before beg))) | |||
| (if (and company-elisp-detect-function-context | |||
| (not (memq before '(?' ?`)))) | |||
| (if (and (eq before ?\() | |||
| (not | |||
| (save-excursion | |||
| (ignore-errors | |||
| (goto-char (1- beg)) | |||
| (or (company-elisp--before-binding-varlist-p) | |||
| (progn | |||
| (up-list -1) | |||
| (company-elisp--before-binding-varlist-p))))))) | |||
| 'fboundp | |||
| 'boundp) | |||
| 'company-elisp--predicate))) | |||
| (defun company-elisp--before-binding-varlist-p () | |||
| (save-excursion | |||
| (and (prog1 (search-backward "(") | |||
| (forward-char 1)) | |||
| (looking-at company-elisp-var-binding-regexp)))) | |||
| (defun company-elisp--doc (symbol) | |||
| (let* ((symbol (intern symbol)) | |||
| (doc (if (fboundp symbol) | |||
| (documentation symbol t) | |||
| (documentation-property symbol 'variable-documentation t)))) | |||
| (and (stringp doc) | |||
| (string-match ".*$" doc) | |||
| (match-string 0 doc)))) | |||
| ;;;###autoload | |||
| (defun company-elisp (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for Emacs Lisp." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-elisp)) | |||
| (prefix (and (derived-mode-p 'emacs-lisp-mode 'inferior-emacs-lisp-mode) | |||
| (company-elisp--prefix))) | |||
| (candidates (company-elisp-candidates arg)) | |||
| (sorted company-elisp-show-locals-first) | |||
| (meta (company-elisp--doc arg)) | |||
| (doc-buffer (let ((symbol (intern arg))) | |||
| (save-window-excursion | |||
| (ignore-errors | |||
| (cond | |||
| ((fboundp symbol) (describe-function symbol)) | |||
| ((boundp symbol) (describe-variable symbol)) | |||
| ((featurep symbol) (describe-package symbol)) | |||
| ((facep symbol) (describe-face symbol)) | |||
| (t (signal 'user-error nil))) | |||
| (help-buffer))))) | |||
| (location (let ((sym (intern arg))) | |||
| (cond | |||
| ((fboundp sym) (find-definition-noselect sym nil)) | |||
| ((boundp sym) (find-definition-noselect sym 'defvar)) | |||
| ((featurep sym) (cons (find-file-noselect (find-library-name | |||
| (symbol-name sym))) | |||
| 0)) | |||
| ((facep sym) (find-definition-noselect sym 'defface))))))) | |||
| (provide 'company-elisp) | |||
| ;;; company-elisp.el ends here | |||
| @ -0,0 +1,94 @@ | |||
| ;;; company-etags.el --- company-mode completion back-end for etags | |||
| ;; Copyright (C) 2009-2011, 2014 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (require 'etags) | |||
| (defgroup company-etags nil | |||
| "Completion back-end for etags." | |||
| :group 'company) | |||
| (defcustom company-etags-use-main-table-list t | |||
| "Always search `tags-table-list' if set. | |||
| If this is disabled, `company-etags' will try to find the one table for each | |||
| buffer automatically." | |||
| :type '(choice (const :tag "off" nil) | |||
| (const :tag "on" t))) | |||
| (defcustom company-etags-ignore-case nil | |||
| "Non-nil to ignore case in completion candidates." | |||
| :type 'boolean) | |||
| (defvar company-etags-modes '(prog-mode c-mode objc-mode c++-mode java-mode | |||
| jde-mode pascal-mode perl-mode python-mode)) | |||
| (defvar company-etags-buffer-table 'unknown) | |||
| (make-variable-buffer-local 'company-etags-buffer-table) | |||
| (defun company-etags-find-table () | |||
| (let ((file (locate-dominating-file (or buffer-file-name | |||
| default-directory) | |||
| "TAGS"))) | |||
| (when file | |||
| (list (expand-file-name file))))) | |||
| (defun company-etags-buffer-table () | |||
| (or (and company-etags-use-main-table-list tags-table-list) | |||
| (if (eq company-etags-buffer-table 'unknown) | |||
| (setq company-etags-buffer-table (company-etags-find-table)) | |||
| company-etags-buffer-table))) | |||
| (defun company-etags--candidates (prefix) | |||
| (let ((tags-table-list (company-etags-buffer-table)) | |||
| (completion-ignore-case company-etags-ignore-case)) | |||
| (and (or tags-file-name tags-table-list) | |||
| (fboundp 'tags-completion-table) | |||
| (save-excursion | |||
| (visit-tags-table-buffer) | |||
| (all-completions prefix (tags-completion-table)))))) | |||
| ;;;###autoload | |||
| (defun company-etags (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for etags." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-etags)) | |||
| (prefix (and (apply 'derived-mode-p company-etags-modes) | |||
| (not (company-in-string-or-comment)) | |||
| (company-etags-buffer-table) | |||
| (or (company-grab-symbol) 'stop))) | |||
| (candidates (company-etags--candidates arg)) | |||
| (location (let ((tags-table-list (company-etags-buffer-table))) | |||
| (when (fboundp 'find-tag-noselect) | |||
| (save-excursion | |||
| (let ((buffer (find-tag-noselect arg))) | |||
| (cons buffer (with-current-buffer buffer (point)))))))) | |||
| (ignore-case company-etags-ignore-case))) | |||
| (provide 'company-etags) | |||
| ;;; company-etags.el ends here | |||
| @ -0,0 +1,91 @@ | |||
| ;;; company-files.el --- company-mode completion back-end for file names | |||
| ;; Copyright (C) 2009-2011, 2013 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (defun company-files-directory-files (dir prefix) | |||
| (ignore-errors | |||
| (if (equal prefix "") | |||
| (directory-files dir nil "\\`[^.]\\|\\`.[^.]") | |||
| (file-name-all-completions prefix dir)))) | |||
| (defvar company-files-regexps | |||
| (let ((begin (if (eq system-type 'windows-nt) | |||
| "[a-z][A-Z]\\" | |||
| "~?/"))) | |||
| (list (concat "\"\\(" begin "[^\"\n]*\\)") | |||
| (concat "\'\\(" begin "[^\'\n]*\\)") | |||
| (concat "\\(?:[ \t]\\|^\\)\\(" begin "[^ \t\n]*\\)")))) | |||
| (defun company-files-grab-existing-name () | |||
| ;; Grab file names with spaces, only when they include quotes. | |||
| (let (file dir) | |||
| (and (cl-dolist (regexp company-files-regexps) | |||
| (when (setq file (company-grab-line regexp 1)) | |||
| (cl-return file))) | |||
| (setq dir (file-name-directory file)) | |||
| (not (string-match "//" dir)) | |||
| (file-exists-p dir) | |||
| (file-name-all-completions (file-name-nondirectory file) dir) | |||
| file))) | |||
| (defvar company-files-completion-cache nil) | |||
| (defun company-files-complete (prefix) | |||
| (let* ((dir (file-name-directory prefix)) | |||
| (file (file-name-nondirectory prefix)) | |||
| candidates) | |||
| (unless (equal dir (car company-files-completion-cache)) | |||
| (dolist (file (company-files-directory-files dir file)) | |||
| (setq file (concat dir file)) | |||
| (push file candidates) | |||
| (when (file-directory-p file) | |||
| ;; Add one level of children. | |||
| (dolist (child (company-files-directory-files file "")) | |||
| (push (concat file | |||
| (unless (eq (aref file (1- (length file))) ?/) "/") | |||
| child) candidates)))) | |||
| (setq company-files-completion-cache (cons dir (nreverse candidates)))) | |||
| (all-completions prefix | |||
| (cdr company-files-completion-cache)))) | |||
| ;;;###autoload | |||
| (defun company-files (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end existing file names." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-files)) | |||
| (prefix (company-files-grab-existing-name)) | |||
| (candidates (company-files-complete arg)) | |||
| (location (cons (dired-noselect | |||
| (file-name-directory (directory-file-name arg))) 1)) | |||
| (sorted t) | |||
| (no-cache t))) | |||
| (provide 'company-files) | |||
| ;;; company-files.el ends here | |||
| @ -0,0 +1,90 @@ | |||
| ;;; company-gtags.el --- company-mode completion back-end for GNU Global | |||
| ;; Copyright (C) 2009-2011 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (defgroup company-gtags nil | |||
| "Completion back-end for GNU Global." | |||
| :group 'company) | |||
| (defcustom company-gtags-executable | |||
| (executable-find "global") | |||
| "Location of GNU global executable." | |||
| :type 'string) | |||
| (define-obsolete-variable-alias | |||
| 'company-gtags-gnu-global-program-name | |||
| 'company-gtags-executable "earlier") | |||
| (defvar company-gtags--tags-available-p 'unknown) | |||
| (make-variable-buffer-local 'company-gtags--tags-available-p) | |||
| (defvar company-gtags-modes '(c-mode c++-mode jde-mode java-mode php-mode)) | |||
| (defun company-gtags--tags-available-p () | |||
| (if (eq company-gtags--tags-available-p 'unknown) | |||
| (setq company-gtags--tags-available-p | |||
| (locate-dominating-file buffer-file-name "GTAGS")) | |||
| company-gtags--tags-available-p)) | |||
| (defun company-gtags-fetch-tags (prefix) | |||
| (with-temp-buffer | |||
| (let (tags) | |||
| (when (= 0 (call-process company-gtags-executable nil | |||
| (list (current-buffer) nil) nil "-c" prefix)) | |||
| (goto-char (point-min)) | |||
| (split-string (buffer-string) "\n" t))))) | |||
| (defun company-gtags-location (tag) | |||
| (with-temp-buffer | |||
| (when (= 0 (call-process company-gtags-executable nil | |||
| (list (current-buffer) nil) nil "-x" tag)) | |||
| (goto-char (point-min)) | |||
| (when (looking-at (concat (regexp-quote tag) | |||
| "[ \t]+\\([[:digit:]]+\\)" | |||
| "[ \t]+\\([^ \t]+\\)")) | |||
| (cons (expand-file-name (match-string 2)) | |||
| (string-to-number (match-string 1))))))) | |||
| ;;;###autoload | |||
| (defun company-gtags (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for GNU Global." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-gtags)) | |||
| (prefix (and company-gtags-executable | |||
| (memq major-mode company-gtags-modes) | |||
| (not (company-in-string-or-comment)) | |||
| (company-gtags--tags-available-p) | |||
| (or (company-grab-symbol) 'stop))) | |||
| (candidates (company-gtags-fetch-tags arg)) | |||
| (sorted t) | |||
| (location (company-gtags-location arg)))) | |||
| (provide 'company-gtags) | |||
| ;;; company-gtags.el ends here | |||
| @ -0,0 +1,69 @@ | |||
| ;;; company-ispell.el --- company-mode completion back-end using Ispell | |||
| ;; Copyright (C) 2009-2011 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (require 'ispell) | |||
| (defgroup company-ispell nil | |||
| "Completion back-end using Ispell." | |||
| :group 'company) | |||
| (defcustom company-ispell-dictionary nil | |||
| "Dictionary to use for `company-ispell'. | |||
| If nil, use `ispell-complete-word-dict'." | |||
| :type '(choice (const :tag "default (nil)" nil) | |||
| (file :tag "dictionary" t))) | |||
| (defvar company-ispell-available 'unknown) | |||
| (defun company-ispell-available () | |||
| (when (eq company-ispell-available 'unknown) | |||
| (condition-case err | |||
| (progn | |||
| (lookup-words "WHATEVER") | |||
| (setq company-ispell-available t)) | |||
| (error | |||
| (message "Company: ispell-look-command not found") | |||
| (setq company-ispell-available nil)))) | |||
| company-ispell-available) | |||
| ;;;###autoload | |||
| (defun company-ispell (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end using Ispell." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-ispell)) | |||
| (prefix (when (company-ispell-available) | |||
| (company-grab-word))) | |||
| (candidates (lookup-words arg (or company-ispell-dictionary | |||
| ispell-complete-word-dict))) | |||
| (sorted t) | |||
| (ignore-case 'keep-prefix))) | |||
| (provide 'company-ispell) | |||
| ;;; company-ispell.el ends here | |||
| @ -0,0 +1,235 @@ | |||
| ;;; company-keywords.el --- A company back-end for programming language keywords | |||
| ;; Copyright (C) 2009-2011 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (defun company-keywords-upper-lower (&rest lst) | |||
| ;; Upcase order is different for _. | |||
| (nconc (sort (mapcar 'upcase lst) 'string<) lst)) | |||
| (defvar company-keywords-alist | |||
| ;; Please contribute corrections or additions. | |||
| `((c++-mode | |||
| "asm" "auto" "bool" "break" "case" "catch" "char" "class" "const" | |||
| "const_cast" "continue" "default" "delete" "do" "double" "dynamic_cast" | |||
| "else" "enum" "explicit" "export" "extern" "false" "float" "for" "friend" | |||
| "goto" "if" "inline" "int" "long" "mutable" "namespace" "new" | |||
| "operator" "private" "protected" "public" "register" "reinterpret_cast" | |||
| "return" "short" "signed" "sizeof" "static" "static_cast" "struct" "switch" | |||
| "template" "this" "throw" "true" "try" "typedef" "typeid" "typename" | |||
| "union" "unsigned" "using" "virtual" "void" "volatile" "wchar_t" "while") | |||
| (c-mode | |||
| "auto" "break" "case" "char" "const" "continue" "default" "do" | |||
| "double" "else" "enum" "extern" "float" "for" "goto" "if" "int" "long" | |||
| "register" "return" "short" "signed" "sizeof" "static" "struct" | |||
| "switch" "typedef" "union" "unsigned" "void" "volatile" "while") | |||
| (csharp-mode | |||
| "abstract" "add" "alias" "as" "base" "bool" "break" "byte" "case" | |||
| "catch" "char" "checked" "class" "const" "continue" "decimal" "default" | |||
| "delegate" "do" "double" "else" "enum" "event" "explicit" "extern" | |||
| "false" "finally" "fixed" "float" "for" "foreach" "get" "global" "goto" | |||
| "if" "implicit" "in" "int" "interface" "internal" "is" "lock" "long" | |||
| "namespace" "new" "null" "object" "operator" "out" "override" "params" | |||
| "partial" "private" "protected" "public" "readonly" "ref" "remove" | |||
| "return" "sbyte" "sealed" "set" "short" "sizeof" "stackalloc" "static" | |||
| "string" "struct" "switch" "this" "throw" "true" "try" "typeof" "uint" | |||
| "ulong" "unchecked" "unsafe" "ushort" "using" "value" "var" "virtual" | |||
| "void" "volatile" "where" "while" "yield") | |||
| (d-mode | |||
| ;; from http://www.digitalmars.com/d/2.0/lex.html | |||
| "abstract" "alias" "align" "asm" | |||
| "assert" "auto" "body" "bool" "break" "byte" "case" "cast" "catch" | |||
| "cdouble" "cent" "cfloat" "char" "class" "const" "continue" "creal" | |||
| "dchar" "debug" "default" "delegate" "delete" "deprecated" "do" | |||
| "double" "else" "enum" "export" "extern" "false" "final" "finally" | |||
| "float" "for" "foreach" "foreach_reverse" "function" "goto" "idouble" | |||
| "if" "ifloat" "import" "in" "inout" "int" "interface" "invariant" | |||
| "ireal" "is" "lazy" "long" "macro" "mixin" "module" "new" "nothrow" | |||
| "null" "out" "override" "package" "pragma" "private" "protected" | |||
| "public" "pure" "real" "ref" "return" "scope" "short" "static" "struct" | |||
| "super" "switch" "synchronized" "template" "this" "throw" "true" "try" | |||
| "typedef" "typeid" "typeof" "ubyte" "ucent" "uint" "ulong" "union" | |||
| "unittest" "ushort" "version" "void" "volatile" "wchar" "while" "with") | |||
| (f90-mode . | |||
| ;; from f90.el | |||
| ;; ".AND." ".GE." ".GT." ".LT." ".LE." ".NE." ".OR." ".TRUE." ".FALSE." | |||
| ,(company-keywords-upper-lower | |||
| "abs" "abstract" "achar" "acos" "adjustl" "adjustr" "aimag" "aint" | |||
| "align" "all" "all_prefix" "all_scatter" "all_suffix" "allocatable" | |||
| "allocate" "allocated" "and" "anint" "any" "any_prefix" "any_scatter" | |||
| "any_suffix" "asin" "assign" "assignment" "associate" "associated" | |||
| "asynchronous" "atan" "atan2" "backspace" "bind" "bit_size" "block" | |||
| "btest" "c_alert" "c_associated" "c_backspace" "c_bool" | |||
| "c_carriage_return" "c_char" "c_double" "c_double_complex" "c_f_pointer" | |||
| "c_f_procpointer" "c_float" "c_float_complex" "c_form_feed" "c_funloc" | |||
| "c_funptr" "c_horizontal_tab" "c_int" "c_int16_t" "c_int32_t" "c_int64_t" | |||
| "c_int8_t" "c_int_fast16_t" "c_int_fast32_t" "c_int_fast64_t" | |||
| "c_int_fast8_t" "c_int_least16_t" "c_int_least32_t" "c_int_least64_t" | |||
| "c_int_least8_t" "c_intmax_t" "c_intptr_t" "c_loc" "c_long" | |||
| "c_long_double" "c_long_double_complex" "c_long_long" "c_new_line" | |||
| "c_null_char" "c_null_funptr" "c_null_ptr" "c_ptr" "c_short" | |||
| "c_signed_char" "c_size_t" "c_vertical_tab" "call" "case" "ceiling" | |||
| "char" "character" "character_storage_size" "class" "close" "cmplx" | |||
| "command_argument_count" "common" "complex" "conjg" "contains" "continue" | |||
| "copy_prefix" "copy_scatter" "copy_suffix" "cos" "cosh" "count" | |||
| "count_prefix" "count_scatter" "count_suffix" "cpu_time" "cshift" | |||
| "cycle" "cyclic" "data" "date_and_time" "dble" "deallocate" "deferred" | |||
| "digits" "dim" "dimension" "distribute" "do" "dot_product" "double" | |||
| "dprod" "dynamic" "elemental" "else" "elseif" "elsewhere" "end" "enddo" | |||
| "endfile" "endif" "entry" "enum" "enumerator" "eoshift" "epsilon" "eq" | |||
| "equivalence" "eqv" "error_unit" "exit" "exp" "exponent" "extends" | |||
| "extends_type_of" "external" "extrinsic" "false" "file_storage_size" | |||
| "final" "floor" "flush" "forall" "format" "fraction" "function" "ge" | |||
| "generic" "get_command" "get_command_argument" "get_environment_variable" | |||
| "goto" "grade_down" "grade_up" "gt" "hpf_alignment" "hpf_distribution" | |||
| "hpf_template" "huge" "iachar" "iall" "iall_prefix" "iall_scatter" | |||
| "iall_suffix" "iand" "iany" "iany_prefix" "iany_scatter" "iany_suffix" | |||
| "ibclr" "ibits" "ibset" "ichar" "ieee_arithmetic" "ieee_exceptions" | |||
| "ieee_features" "ieee_get_underflow_mode" "ieee_set_underflow_mode" | |||
| "ieee_support_underflow_control" "ieor" "if" "ilen" "implicit" | |||
| "import" "include" "independent" "index" "inherit" "input_unit" | |||
| "inquire" "int" "integer" "intent" "interface" "intrinsic" "ior" | |||
| "iostat_end" "iostat_eor" "iparity" "iparity_prefix" "iparity_scatter" | |||
| "iparity_suffix" "ishft" "ishftc" "iso_c_binding" "iso_fortran_env" | |||
| "kind" "lbound" "le" "leadz" "len" "len_trim" "lge" "lgt" "lle" "llt" | |||
| "log" "log10" "logical" "lt" "matmul" "max" "maxexponent" "maxloc" | |||
| "maxval" "maxval_prefix" "maxval_scatter" "maxval_suffix" "merge" | |||
| "min" "minexponent" "minloc" "minval" "minval_prefix" "minval_scatter" | |||
| "minval_suffix" "mod" "module" "modulo" "move_alloc" "mvbits" "namelist" | |||
| "ne" "nearest" "neqv" "new" "new_line" "nint" "non_intrinsic" | |||
| "non_overridable" "none" "nopass" "not" "null" "nullify" | |||
| "number_of_processors" "numeric_storage_size" "only" "onto" "open" | |||
| "operator" "optional" "or" "output_unit" "pack" "parameter" "parity" | |||
| "parity_prefix" "parity_scatter" "parity_suffix" "pass" "pause" | |||
| "pointer" "popcnt" "poppar" "precision" "present" "print" "private" | |||
| "procedure" "processors" "processors_shape" "product" "product_prefix" | |||
| "product_scatter" "product_suffix" "program" "protected" "public" | |||
| "pure" "radix" "random_number" "random_seed" "range" "read" "real" | |||
| "realign" "recursive" "redistribute" "repeat" "reshape" "result" | |||
| "return" "rewind" "rrspacing" "same_type_as" "save" "scale" "scan" | |||
| "select" "selected_char_kind" "selected_int_kind" "selected_real_kind" | |||
| "sequence" "set_exponent" "shape" "sign" "sin" "sinh" "size" "spacing" | |||
| "spread" "sqrt" "stop" "subroutine" "sum" "sum_prefix" "sum_scatter" | |||
| "sum_suffix" "system_clock" "tan" "tanh" "target" "template" "then" | |||
| "tiny" "transfer" "transpose" "trim" "true" "type" "ubound" "unpack" | |||
| "use" "value" "verify" "volatile" "wait" "where" "while" "with" "write")) | |||
| (java-mode | |||
| "abstract" "assert" "boolean" "break" "byte" "case" "catch" "char" "class" | |||
| "continue" "default" "do" "double" "else" "enum" "extends" "final" | |||
| "finally" "float" "for" "if" "implements" "import" "instanceof" "int" | |||
| "interface" "long" "native" "new" "package" "private" "protected" "public" | |||
| "return" "short" "static" "strictfp" "super" "switch" "synchronized" | |||
| "this" "throw" "throws" "transient" "try" "void" "volatile" "while") | |||
| (javascript-mode | |||
| "break" "catch" "const" "continue" "delete" "do" "else" "export" "for" | |||
| "function" "if" "import" "in" "instanceOf" "label" "let" "new" "return" | |||
| "switch" "this" "throw" "try" "typeof" "var" "void" "while" "with" "yield") | |||
| (objc-mode | |||
| "@catch" "@class" "@encode" "@end" "@finally" "@implementation" | |||
| "@interface" "@private" "@protected" "@protocol" "@public" | |||
| "@selector" "@synchronized" "@throw" "@try" "alloc" "autorelease" | |||
| "bycopy" "byref" "in" "inout" "oneway" "out" "release" "retain") | |||
| (perl-mode | |||
| ;; from cperl.el | |||
| "AUTOLOAD" "BEGIN" "CHECK" "CORE" "DESTROY" "END" "INIT" "__END__" | |||
| "__FILE__" "__LINE__" "abs" "accept" "alarm" "and" "atan2" "bind" | |||
| "binmode" "bless" "caller" "chdir" "chmod" "chomp" "chop" "chown" "chr" | |||
| "chroot" "close" "closedir" "cmp" "connect" "continue" "cos" | |||
| "crypt" "dbmclose" "dbmopen" "defined" "delete" "die" "do" "dump" "each" | |||
| "else" "elsif" "endgrent" "endhostent" "endnetent" "endprotoent" | |||
| "endpwent" "endservent" "eof" "eq" "eval" "exec" "exists" "exit" "exp" | |||
| "fcntl" "fileno" "flock" "for" "foreach" "fork" "format" "formline" | |||
| "ge" "getc" "getgrent" "getgrgid" "getgrnam" "gethostbyaddr" | |||
| "gethostbyname" "gethostent" "getlogin" "getnetbyaddr" "getnetbyname" | |||
| "getnetent" "getpeername" "getpgrp" "getppid" "getpriority" | |||
| "getprotobyname" "getprotobynumber" "getprotoent" "getpwent" "getpwnam" | |||
| "getpwuid" "getservbyname" "getservbyport" "getservent" "getsockname" | |||
| "getsockopt" "glob" "gmtime" "goto" "grep" "gt" "hex" "if" "index" "int" | |||
| "ioctl" "join" "keys" "kill" "last" "lc" "lcfirst" "le" "length" | |||
| "link" "listen" "local" "localtime" "lock" "log" "lstat" "lt" "map" | |||
| "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "my" "ne" "next" "no" | |||
| "not" "oct" "open" "opendir" "or" "ord" "our" "pack" "package" "pipe" | |||
| "pop" "pos" "print" "printf" "push" "q" "qq" "quotemeta" "qw" "qx" | |||
| "rand" "read" "readdir" "readline" "readlink" "readpipe" "recv" "redo" | |||
| "ref" "rename" "require" "reset" "return" "reverse" "rewinddir" "rindex" | |||
| "rmdir" "scalar" "seek" "seekdir" "select" "semctl" "semget" "semop" | |||
| "send" "setgrent" "sethostent" "setnetent" "setpgrp" "setpriority" | |||
| "setprotoent" "setpwent" "setservent" "setsockopt" "shift" "shmctl" | |||
| "shmget" "shmread" "shmwrite" "shutdown" "sin" "sleep" "socket" | |||
| "socketpair" "sort" "splice" "split" "sprintf" "sqrt" "srand" "stat" | |||
| "study" "sub" "substr" "symlink" "syscall" "sysopen" "sysread" "system" | |||
| "syswrite" "tell" "telldir" "tie" "time" "times" "tr" "truncate" "uc" | |||
| "ucfirst" "umask" "undef" "unless" "unlink" "unpack" "unshift" "untie" | |||
| "until" "use" "utime" "values" "vec" "wait" "waitpid" | |||
| "wantarray" "warn" "while" "write" "x" "xor" "y") | |||
| (php-mode | |||
| "__CLASS__" "__DIR__" "__FILE__" "__FUNCTION__" "__LINE__" "__METHOD__" | |||
| "__NAMESPACE__" "_once" "abstract" "and" "array" "as" "break" "case" | |||
| "catch" "cfunction" "class" "clone" "const" "continue" "declare" | |||
| "default" "die" "do" "echo" "else" "elseif" "empty" "enddeclare" | |||
| "endfor" "endforeach" "endif" "endswitch" "endwhile" "eval" "exception" | |||
| "exit" "extends" "final" "for" "foreach" "function" "global" | |||
| "goto" "if" "implements" "include" "instanceof" "interface" | |||
| "isset" "list" "namespace" "new" "old_function" "or" "php_user_filter" | |||
| "print" "private" "protected" "public" "require" "require_once" "return" | |||
| "static" "switch" "this" "throw" "try" "unset" "use" "var" "while" "xor") | |||
| (python-mode | |||
| "and" "assert" "break" "class" "continue" "def" "del" "elif" "else" | |||
| "except" "exec" "finally" "for" "from" "global" "if" "import" "in" "is" | |||
| "lambda" "not" "or" "pass" "print" "raise" "return" "try" "while" "yield") | |||
| (ruby-mode | |||
| "BEGIN" "END" "alias" "and" "begin" "break" "case" "class" "def" "defined?" | |||
| "do" "else" "elsif" "end" "ensure" "false" "for" "if" "in" "module" | |||
| "next" "nil" "not" "or" "redo" "rescue" "retry" "return" "self" "super" | |||
| "then" "true" "undef" "unless" "until" "when" "while" "yield") | |||
| ;; aliases | |||
| (js2-mode . javascript-mode) | |||
| (espresso-mode . javascript-mode) | |||
| (cperl-mode . perl-mode) | |||
| (jde-mode . java-mode)) | |||
| "Alist mapping major-modes to sorted keywords for `company-keywords'.") | |||
| ;;;###autoload | |||
| (defun company-keywords (command &optional arg &rest ignored) | |||
| "`company-mode' back-end for programming language keywords." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-keywords)) | |||
| (prefix (and (assq major-mode company-keywords-alist) | |||
| (not (company-in-string-or-comment)) | |||
| (or (company-grab-symbol) 'stop))) | |||
| (candidates | |||
| (let ((completion-ignore-case nil) | |||
| (symbols (cdr (assq major-mode company-keywords-alist)))) | |||
| (all-completions arg (if (consp symbols) | |||
| symbols | |||
| (cdr (assq symbols company-keywords-alist)))))) | |||
| (sorted t))) | |||
| (provide 'company-keywords) | |||
| ;;; company-keywords.el ends here | |||
| @ -0,0 +1,142 @@ | |||
| ;;; company-nxml.el --- company-mode completion back-end for nxml-mode | |||
| ;; Copyright (C) 2009-2011, 2013 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (defvar rng-open-elements) | |||
| (defvar rng-validate-mode) | |||
| (defvar rng-in-attribute-regex) | |||
| (defvar rng-in-attribute-value-regex) | |||
| (declare-function rng-set-state-after "rng-nxml") | |||
| (declare-function rng-match-possible-start-tag-names "rng-match") | |||
| (declare-function rng-adjust-state-for-attribute "rng-nxml") | |||
| (declare-function rng-match-possible-attribute-names "rng-match") | |||
| (declare-function rng-adjust-state-for-attribute-value "rng-nxml") | |||
| (declare-function rng-match-possible-value-strings "rng-match") | |||
| (defconst company-nxml-token-regexp | |||
| "\\(?:[_[:alpha:]][-._[:alnum:]]*\\_>\\)") | |||
| (defvar company-nxml-in-attribute-value-regexp | |||
| (replace-regexp-in-string "w" company-nxml-token-regexp | |||
| "<w\\(?::w\\)?\ | |||
| \\(?:[ \t\r\n]+w\\(?::w\\)?[ \t\r\n]*=\ | |||
| \[ \t\r\n]*\\(?:\"[^\"]*\"\\|'[^']*'\\)\\)*\ | |||
| \[ \t\r\n]+\\(w\\(:w\\)?\\)[ \t\r\n]*=[ \t\r\n]*\ | |||
| \\(\"\\([^\"]*\\>\\)\\|'\\([^']*\\>\\)\\)\\=" | |||
| t t)) | |||
| (defvar company-nxml-in-tag-name-regexp | |||
| (replace-regexp-in-string "w" company-nxml-token-regexp | |||
| "<\\(/?w\\(?::w?\\)?\\)?\\=" t t)) | |||
| (defun company-nxml-all-completions (prefix alist) | |||
| (let ((candidates (mapcar 'cdr alist)) | |||
| (case-fold-search nil) | |||
| filtered) | |||
| (when (cdar rng-open-elements) | |||
| (push (concat "/" (cdar rng-open-elements)) candidates)) | |||
| (setq candidates (sort (all-completions prefix candidates) 'string<)) | |||
| (while candidates | |||
| (unless (equal (car candidates) (car filtered)) | |||
| (push (car candidates) filtered)) | |||
| (pop candidates)) | |||
| (nreverse filtered))) | |||
| (defmacro company-nxml-prepared (&rest body) | |||
| (declare (indent 0) (debug t)) | |||
| `(let ((lt-pos (save-excursion (search-backward "<" nil t))) | |||
| xmltok-dtd) | |||
| (when (and lt-pos (= (rng-set-state-after lt-pos) lt-pos)) | |||
| ,@body))) | |||
| (defun company-nxml-tag (command &optional arg &rest ignored) | |||
| (cl-case command | |||
| (prefix (and (derived-mode-p 'nxml-mode) | |||
| rng-validate-mode | |||
| (company-grab company-nxml-in-tag-name-regexp 1))) | |||
| (candidates (company-nxml-prepared | |||
| (company-nxml-all-completions | |||
| arg (rng-match-possible-start-tag-names)))) | |||
| (sorted t))) | |||
| (defun company-nxml-attribute (command &optional arg &rest ignored) | |||
| (cl-case command | |||
| (prefix (and (derived-mode-p 'nxml-mode) | |||
| rng-validate-mode | |||
| (memq (char-after) '(?\ ?\t ?\n)) ;; outside word | |||
| (company-grab rng-in-attribute-regex 1))) | |||
| (candidates (company-nxml-prepared | |||
| (and (rng-adjust-state-for-attribute | |||
| lt-pos (- (point) (length arg))) | |||
| (company-nxml-all-completions | |||
| arg (rng-match-possible-attribute-names))))) | |||
| (sorted t))) | |||
| (defun company-nxml-attribute-value (command &optional arg &rest ignored) | |||
| (cl-case command | |||
| (prefix (and (derived-mode-p 'nxml-mode) | |||
| rng-validate-mode | |||
| (and (memq (char-after) '(?' ?\" ?\ ?\t ?\n)) ;; outside word | |||
| (looking-back company-nxml-in-attribute-value-regexp) | |||
| (or (match-string-no-properties 4) | |||
| (match-string-no-properties 5) | |||
| "")))) | |||
| (candidates (company-nxml-prepared | |||
| (let (attr-start attr-end colon) | |||
| (and (looking-back rng-in-attribute-value-regex lt-pos) | |||
| (setq colon (match-beginning 2) | |||
| attr-start (match-beginning 1) | |||
| attr-end (match-end 1)) | |||
| (rng-adjust-state-for-attribute lt-pos attr-start) | |||
| (rng-adjust-state-for-attribute-value | |||
| attr-start colon attr-end) | |||
| (all-completions | |||
| arg (rng-match-possible-value-strings)))))))) | |||
| ;;;###autoload | |||
| (defun company-nxml (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for `nxml-mode'." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-nxml)) | |||
| (prefix (or (company-nxml-tag 'prefix) | |||
| (company-nxml-attribute 'prefix) | |||
| (company-nxml-attribute-value 'prefix))) | |||
| (candidates (cond | |||
| ((company-nxml-tag 'prefix) | |||
| (company-nxml-tag 'candidates arg)) | |||
| ((company-nxml-attribute 'prefix) | |||
| (company-nxml-attribute 'candidates arg)) | |||
| ((company-nxml-attribute-value 'prefix) | |||
| (sort (company-nxml-attribute-value 'candidates arg) | |||
| 'string<)))) | |||
| (sorted t))) | |||
| (provide 'company-nxml) | |||
| ;;; company-nxml.el ends here | |||
| @ -0,0 +1,57 @@ | |||
| ;;; company-oddmuse.el --- company-mode completion back-end for oddmuse-mode | |||
| ;; Copyright (C) 2009-2011, 2014 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (eval-when-compile (require 'yaooddmuse nil t)) | |||
| (eval-when-compile (require 'oddmuse nil t)) | |||
| (defvar company-oddmuse-link-regexp | |||
| "\\(\\<[A-Z][[:alnum:]]*\\>\\)\\|\\[\\[\\([[:alnum:]]+\\>\\|\\)") | |||
| (defun company-oddmuse-get-page-table () | |||
| (cl-case major-mode | |||
| (yaoddmuse-mode (with-no-warnings | |||
| (yaoddmuse-get-pagename-table yaoddmuse-wikiname))) | |||
| (oddmuse-mode (with-no-warnings | |||
| (oddmuse-make-completion-table oddmuse-wiki))))) | |||
| ;;;###autoload | |||
| (defun company-oddmuse (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for `oddmuse-mode'." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-oddmuse)) | |||
| (prefix (let ((case-fold-search nil)) | |||
| (and (memq major-mode '(oddmuse-mode yaoddmuse-mode)) | |||
| (looking-back company-oddmuse-link-regexp (point-at-bol)) | |||
| (or (match-string 1) | |||
| (match-string 2))))) | |||
| (candidates (all-completions arg (company-oddmuse-get-page-table))))) | |||
| (provide 'company-oddmuse) | |||
| ;;; company-oddmuse.el ends here | |||
| @ -0,0 +1 @@ | |||
| (define-package "company" "0.8.0" "Modular text completion framework" '((emacs "24.1") (cl-lib "0.5")) :keywords ("abbrev" "convenience" "matching") :url "http://company-mode.github.io/") | |||
| @ -0,0 +1,69 @@ | |||
| ;;; company-pysmell.el --- company-mode completion back-end for pysmell.el | |||
| ;; Copyright (C) 2009-2011, 2013-2014 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;; The main problem with using this backend is installing Pysmell. | |||
| ;; I couldn't manage to do that. --Dmitry | |||
| ;;; Code: | |||
| (if t (require 'pysmell)) ;Don't load during compilation. | |||
| (require 'cl-lib) | |||
| (defvar company-pysmell--available-p 'unknown) | |||
| (make-variable-buffer-local 'company-pysmell--available-p) | |||
| (defun company-pysmell--available-p () | |||
| (if (eq company-pysmell--available-p 'unknown) | |||
| (setq company-pysmell--available-p | |||
| (locate-dominating-file buffer-file-name "PYSMELLTAGS")) | |||
| company-pysmell--available-p)) | |||
| (defun company-pysmell--grab-symbol () | |||
| (let ((symbol (company-grab-symbol))) | |||
| (when symbol | |||
| (cons symbol | |||
| (save-excursion | |||
| (let ((pos (point))) | |||
| (goto-char (- (point) (length symbol))) | |||
| (while (eq (char-before) ?.) | |||
| (goto-char (1- (point))) | |||
| (skip-syntax-backward "w_")) | |||
| (- pos (point)))))))) | |||
| ;;;###autoload | |||
| (defun company-pysmell (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for pysmell. | |||
| This requires pysmell.el and pymacs.el." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-pysmell)) | |||
| (prefix (and (derived-mode-p 'python-mode) | |||
| buffer-file-name | |||
| (not (company-in-string-or-comment)) | |||
| (company-pysmell--available-p) | |||
| (company-pysmell--grab-symbol))) | |||
| (candidates (delete "" (pysmell-get-all-completions))))) | |||
| (provide 'company-pysmell) | |||
| ;;; company-pysmell.el ends here | |||
| @ -0,0 +1,76 @@ | |||
| ;;; company-ropemacs.el --- company-mode completion back-end for ropemacs | |||
| ;; Copyright (C) 2009-2011, 2013 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'cl-lib) | |||
| (defun company-ropemacs--grab-symbol () | |||
| (let ((symbol (company-grab-symbol))) | |||
| (when symbol | |||
| (cons symbol | |||
| (save-excursion | |||
| (let ((pos (point))) | |||
| (goto-char (- (point) (length symbol))) | |||
| (while (eq (char-before) ?.) | |||
| (goto-char (1- (point))) | |||
| (skip-syntax-backward "w_")) | |||
| (- pos (point)))))))) | |||
| (defun company-ropemacs-doc-buffer (candidate) | |||
| "Return buffer with docstring of CANDIDATE if it is available." | |||
| (let ((doc (company-with-candidate-inserted candidate (rope-get-doc)))) | |||
| (when doc | |||
| (company-doc-buffer doc)))) | |||
| (defun company-ropemacs-location (candidate) | |||
| "Return location of CANDIDATE in cons form (FILE . LINE) if it is available." | |||
| (let ((location (company-with-candidate-inserted candidate | |||
| (rope-definition-location)))) | |||
| (when location | |||
| (cons (elt location 0) (elt location 1))))) | |||
| (defun company-ropemacs (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for ropemacs. | |||
| Depends on third-party code: Pymacs (both Python and Emacs packages), | |||
| rope, ropemacs and ropemode." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (init (when (and (derived-mode-p 'python-mode) | |||
| (not (fboundp 'rope-completions))) | |||
| (require 'pymacs) | |||
| (pymacs-load "ropemacs" "rope-"))) | |||
| (interactive (company-begin-backend 'company-ropemacs)) | |||
| (prefix (and (derived-mode-p 'python-mode) | |||
| (not (company-in-string-or-comment)) | |||
| (company-ropemacs--grab-symbol))) | |||
| (candidates (mapcar (lambda (element) (concat arg element)) | |||
| (rope-completions))) | |||
| (doc-buffer (company-ropemacs-doc-buffer arg)) | |||
| (location (company-ropemacs-location arg)))) | |||
| (provide 'company-ropemacs) | |||
| ;;; company-ropemacs.el ends here | |||
| @ -0,0 +1,147 @@ | |||
| ;;; company-semantic.el --- company-mode completion back-end using Semantic | |||
| ;; Copyright (C) 2009-2011, 2013 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (defvar semantic-idle-summary-function) | |||
| (declare-function semantic-documentation-for-tag "semantic/doc" ) | |||
| (declare-function semantic-analyze-current-context "semantic/analyze") | |||
| (declare-function semantic-analyze-possible-completions "semantic/complete") | |||
| (declare-function semantic-analyze-find-tags-by-prefix "semantic/analyze/fcn") | |||
| (declare-function semantic-tag-class "semantic/tag") | |||
| (declare-function semantic-tag-name "semantic/tag") | |||
| (declare-function semantic-tag-start "semantic/tag") | |||
| (declare-function semantic-tag-buffer "semantic/tag") | |||
| (declare-function semantic-active-p "semantic") | |||
| (defgroup company-semantic nil | |||
| "Completion back-end using Semantic." | |||
| :group 'company) | |||
| (defcustom company-semantic-metadata-function 'company-semantic-summary-and-doc | |||
| "The function turning a semantic tag into doc information." | |||
| :type 'function) | |||
| (defvar company-semantic-modes '(c-mode c++-mode jde-mode java-mode)) | |||
| (defvar company-semantic--current-tags nil | |||
| "Tags for the current context.") | |||
| (make-variable-buffer-local 'company-semantic--current-tags) | |||
| (defun company-semantic-documentation-for-tag (tag) | |||
| (when (semantic-tag-buffer tag) | |||
| ;; When TAG's buffer is unknown, the function below raises an error. | |||
| (semantic-documentation-for-tag tag))) | |||
| (defun company-semantic-doc-or-summary (tag) | |||
| (or (company-semantic-documentation-for-tag tag) | |||
| (and (require 'semantic-idle nil t) | |||
| (require 'semantic/idle nil t) | |||
| (funcall semantic-idle-summary-function tag nil t)))) | |||
| (defun company-semantic-summary-and-doc (tag) | |||
| (let ((doc (company-semantic-documentation-for-tag tag)) | |||
| (summary (funcall semantic-idle-summary-function tag nil t))) | |||
| (and (stringp doc) | |||
| (string-match "\n*\\(.*\\)$" doc) | |||
| (setq doc (match-string 1 doc))) | |||
| (concat summary | |||
| (when doc | |||
| (if (< (+ (length doc) (length summary) 4) (window-width)) | |||
| " -- " | |||
| "\n")) | |||
| doc))) | |||
| (defun company-semantic-doc-buffer (tag) | |||
| (let ((doc (company-semantic-documentation-for-tag tag))) | |||
| (when doc | |||
| (company-doc-buffer | |||
| (concat (funcall semantic-idle-summary-function tag nil t) | |||
| "\n" | |||
| doc))))) | |||
| (defsubst company-semantic-completions (prefix) | |||
| (ignore-errors | |||
| (let ((completion-ignore-case nil) | |||
| (context (semantic-analyze-current-context))) | |||
| (setq company-semantic--current-tags | |||
| (semantic-analyze-possible-completions context)) | |||
| (all-completions prefix company-semantic--current-tags)))) | |||
| (defun company-semantic-completions-raw (prefix) | |||
| (setq company-semantic--current-tags nil) | |||
| (dolist (tag (semantic-analyze-find-tags-by-prefix prefix)) | |||
| (unless (eq (semantic-tag-class tag) 'include) | |||
| (push tag company-semantic--current-tags))) | |||
| (delete "" (mapcar 'semantic-tag-name company-semantic--current-tags))) | |||
| (defun company-semantic--pre-prefix-length (prefix-length) | |||
| "Sum up the length of all chained symbols before POS. | |||
| Symbols are chained by \".\" or \"->\"." | |||
| (save-excursion | |||
| (let ((pos (point))) | |||
| (goto-char (- (point) prefix-length)) | |||
| (while (looking-back "->\\|\\.") | |||
| (goto-char (match-beginning 0)) | |||
| (skip-syntax-backward "w_")) | |||
| (- pos (point))))) | |||
| (defun company-semantic--grab () | |||
| "Grab the semantic prefix, but return everything before -> or . as length." | |||
| (let ((symbol (company-grab-symbol))) | |||
| (when symbol | |||
| (cons symbol (company-semantic--pre-prefix-length (length symbol)))))) | |||
| ;;;###autoload | |||
| (defun company-semantic (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end using CEDET Semantic." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-semantic)) | |||
| (prefix (and (featurep 'semantic) | |||
| (semantic-active-p) | |||
| (memq major-mode company-semantic-modes) | |||
| (not (company-in-string-or-comment)) | |||
| (or (company-semantic--grab) 'stop))) | |||
| (candidates (if (and (equal arg "") | |||
| (not (looking-back "->\\|\\."))) | |||
| (company-semantic-completions-raw arg) | |||
| (company-semantic-completions arg))) | |||
| (meta (funcall company-semantic-metadata-function | |||
| (assoc arg company-semantic--current-tags))) | |||
| (doc-buffer (company-semantic-doc-buffer | |||
| (assoc arg company-semantic--current-tags))) | |||
| ;; Because "" is an empty context and doesn't return local variables. | |||
| (no-cache (equal arg "")) | |||
| (location (let ((tag (assoc arg company-semantic--current-tags))) | |||
| (when (buffer-live-p (semantic-tag-buffer tag)) | |||
| (cons (semantic-tag-buffer tag) | |||
| (semantic-tag-start tag))))))) | |||
| (provide 'company-semantic) | |||
| ;;; company-semantic.el ends here | |||
| @ -0,0 +1,171 @@ | |||
| ;;; company-template.el | |||
| ;; Copyright (C) 2009, 2010, 2013 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Code: | |||
| (require 'cl-lib) | |||
| (defface company-template-field | |||
| '((((background dark)) (:background "yellow" :foreground "black")) | |||
| (((background light)) (:background "orange" :foreground "black"))) | |||
| "Face used for editable text in template fields." | |||
| :group 'company) | |||
| (defvar company-template-nav-map | |||
| (let ((keymap (make-sparse-keymap))) | |||
| (define-key keymap [tab] 'company-template-forward-field) | |||
| (define-key keymap (kbd "TAB") 'company-template-forward-field) | |||
| keymap)) | |||
| (defvar company-template--buffer-templates nil) | |||
| (make-variable-buffer-local 'company-template--buffer-templates) | |||
| ;; interactive ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |||
| (defun company-template-templates-at (pos) | |||
| (let (os) | |||
| (dolist (o (overlays-at pos)) | |||
| ;; FIXME: Always return the whole list of templates? | |||
| ;; We remove templates not at point after every command. | |||
| (when (memq o company-template--buffer-templates) | |||
| (push o os))) | |||
| os)) | |||
| (defun company-template-move-to-first (templ) | |||
| (interactive) | |||
| (goto-char (overlay-start templ)) | |||
| (company-template-forward-field)) | |||
| (defun company-template-forward-field () | |||
| (interactive) | |||
| (let* ((start (point)) | |||
| (templates (company-template-templates-at (point))) | |||
| (minimum (apply 'max (mapcar 'overlay-end templates))) | |||
| (fields (cl-loop for templ in templates | |||
| append (overlay-get templ 'company-template-fields)))) | |||
| (dolist (pos (mapcar 'overlay-start fields)) | |||
| (and pos | |||
| (> pos (point)) | |||
| (< pos minimum) | |||
| (setq minimum pos))) | |||
| (push-mark) | |||
| (goto-char minimum) | |||
| (company-template-remove-field (company-template-field-at start)))) | |||
| (defun company-template-field-at (&optional point) | |||
| (cl-loop for ovl in (overlays-at (or point (point))) | |||
| when (overlay-get ovl 'company-template-parent) | |||
| return ovl)) | |||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |||
| (defun company-template-declare-template (beg end) | |||
| (let ((ov (make-overlay beg end))) | |||
| ;; (overlay-put ov 'face 'highlight) | |||
| (overlay-put ov 'keymap company-template-nav-map) | |||
| (overlay-put ov 'priority 101) | |||
| (overlay-put ov 'evaporate t) | |||
| (push ov company-template--buffer-templates) | |||
| (add-hook 'post-command-hook 'company-template-post-command nil t) | |||
| ov)) | |||
| (defun company-template-remove-template (templ) | |||
| (mapc 'company-template-remove-field | |||
| (overlay-get templ 'company-template-fields)) | |||
| (setq company-template--buffer-templates | |||
| (delq templ company-template--buffer-templates)) | |||
| (delete-overlay templ)) | |||
| (defun company-template-add-field (templ pos text &optional display) | |||
| "Add new field to template TEMPL at POS, inserting TEXT. | |||
| When DISPLAY is non-nil, set the respective property on the overlay. | |||
| Leave point at the end of the field." | |||
| (cl-assert templ) | |||
| (goto-char pos) | |||
| (insert text) | |||
| (when (> (point) (overlay-end templ)) | |||
| (move-overlay templ (overlay-start templ) (point))) | |||
| (let ((ov (make-overlay pos (+ pos (length text)))) | |||
| (siblings (overlay-get templ 'company-template-fields))) | |||
| ;; (overlay-put ov 'evaporate t) | |||
| (overlay-put ov 'intangible t) | |||
| (overlay-put ov 'face 'company-template-field) | |||
| (when display | |||
| (overlay-put ov 'display display)) | |||
| (overlay-put ov 'company-template-parent templ) | |||
| (overlay-put ov 'insert-in-front-hooks '(company-template-insert-hook)) | |||
| (push ov siblings) | |||
| (overlay-put templ 'company-template-fields siblings))) | |||
| (defun company-template-remove-field (ovl &optional clear) | |||
| (when (overlayp ovl) | |||
| (when (overlay-buffer ovl) | |||
| (when clear | |||
| (delete-region (overlay-start ovl) (overlay-end ovl))) | |||
| (delete-overlay ovl)) | |||
| (let* ((templ (overlay-get ovl 'company-template-parent)) | |||
| (siblings (overlay-get templ 'company-template-fields))) | |||
| (setq siblings (delq ovl siblings)) | |||
| (overlay-put templ 'company-template-fields siblings)))) | |||
| (defun company-template-clean-up (&optional pos) | |||
| "Clean up all templates that don't contain POS." | |||
| (let ((local-ovs (overlays-at (or pos (point))))) | |||
| (dolist (templ company-template--buffer-templates) | |||
| (unless (memq templ local-ovs) | |||
| (company-template-remove-template templ))))) | |||
| ;; hooks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |||
| (defun company-template-insert-hook (ovl after-p &rest _ignore) | |||
| "Called when a snippet input prompt is modified." | |||
| (unless after-p | |||
| (company-template-remove-field ovl t))) | |||
| (defun company-template-post-command () | |||
| (company-template-clean-up) | |||
| (unless company-template--buffer-templates | |||
| (remove-hook 'post-command-hook 'company-template-post-command t))) | |||
| ;; common ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |||
| (defun company-template-c-like-templatify (call) | |||
| (let* ((end (point-marker)) | |||
| (beg (- (point) (length call))) | |||
| (cnt 0)) | |||
| (when (re-search-backward ")" beg t) | |||
| (delete-region (match-end 0) end)) | |||
| (goto-char beg) | |||
| (when (search-forward "(" end 'move) | |||
| (if (eq (char-after) ?\)) | |||
| (forward-char 1) | |||
| (let ((templ (company-template-declare-template beg end))) | |||
| (while (re-search-forward (concat " *\\([^,)]*\\)[,)]") end t) | |||
| (let ((sig (match-string 1))) | |||
| (delete-region (match-beginning 1) (match-end 1)) | |||
| (save-excursion | |||
| (company-template-add-field templ (match-beginning 1) | |||
| (format "arg%d" cnt) sig)) | |||
| (cl-incf cnt))) | |||
| (company-template-move-to-first templ)))))) | |||
| (provide 'company-template) | |||
| ;;; company-template.el ends here | |||
| @ -0,0 +1,63 @@ | |||
| ;;; company-tempo.el --- company-mode completion back-end for tempo | |||
| ;; Copyright (C) 2009-2011 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (require 'tempo) | |||
| (defsubst company-tempo-lookup (match) | |||
| (cdr (assoc match (tempo-build-collection)))) | |||
| (defun company-tempo-insert (match) | |||
| "Replace MATCH with the expanded tempo template." | |||
| (search-backward match) | |||
| (goto-char (match-beginning 0)) | |||
| (replace-match "") | |||
| (call-interactively (company-tempo-lookup match))) | |||
| (defsubst company-tempo-meta (match) | |||
| (let ((templ (company-tempo-lookup match)) | |||
| doc) | |||
| (and templ | |||
| (setq doc (documentation templ t)) | |||
| (car (split-string doc "\n" t))))) | |||
| ;;;###autoload | |||
| (defun company-tempo (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for tempo." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-tempo | |||
| 'company-tempo-insert)) | |||
| (prefix (or (car (tempo-find-match-string tempo-match-finder)) "")) | |||
| (candidates (all-completions arg (tempo-build-collection))) | |||
| (meta (company-tempo-meta arg)) | |||
| (require-match t) | |||
| (sorted t))) | |||
| (provide 'company-tempo) | |||
| ;;; company-tempo.el ends here | |||
| @ -0,0 +1,731 @@ | |||
| ;;; company-tests.el --- company-mode tests -*- lexical-binding: t -*- | |||
| ;; Copyright (C) 2011, 2013-2014 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'ert) | |||
| (require 'company) | |||
| (require 'company-keywords) | |||
| (require 'company-clang) | |||
| ;;; Core | |||
| (ert-deftest company-sorted-keywords () | |||
| "Test that keywords in `company-keywords-alist' are in alphabetical order." | |||
| (dolist (pair company-keywords-alist) | |||
| (when (consp (cdr pair)) | |||
| (let ((prev (cadr pair))) | |||
| (dolist (next (cddr pair)) | |||
| (should (not (equal prev next))) | |||
| (should (string< prev next)) | |||
| (setq prev next)))))) | |||
| (ert-deftest company-good-prefix () | |||
| (let ((company-minimum-prefix-length 5) | |||
| company-abort-manual-when-too-short | |||
| company--manual-action ;idle begin | |||
| (company-selection-changed t)) ;has no effect | |||
| (should (eq t (company--good-prefix-p "!@#$%"))) | |||
| (should (eq nil (company--good-prefix-p "abcd"))) | |||
| (should (eq nil (company--good-prefix-p 'stop))) | |||
| (should (eq t (company--good-prefix-p '("foo" . 5)))) | |||
| (should (eq nil (company--good-prefix-p '("foo" . 4)))) | |||
| (should (eq t (company--good-prefix-p '("foo" . t)))))) | |||
| (ert-deftest company--manual-prefix-set-and-unset () | |||
| (with-temp-buffer | |||
| (insert "ab") | |||
| (company-mode) | |||
| (let (company-frontends | |||
| (company-backends | |||
| (list (lambda (command &optional arg) | |||
| (cl-case command | |||
| (prefix (buffer-substring (point-min) (point))) | |||
| (candidates '("abc" "abd"))))))) | |||
| (company-manual-begin) | |||
| (should (equal "ab" company--manual-prefix)) | |||
| (company-abort) | |||
| (should (null company--manual-prefix))))) | |||
| (ert-deftest company-abort-manual-when-too-short () | |||
| (let ((company-minimum-prefix-length 5) | |||
| (company-abort-manual-when-too-short t) | |||
| (company-selection-changed t)) ;has not effect | |||
| (let ((company--manual-action nil)) ;idle begin | |||
| (should (eq t (company--good-prefix-p "!@#$%"))) | |||
| (should (eq t (company--good-prefix-p '("foo" . 5)))) | |||
| (should (eq t (company--good-prefix-p '("foo" . t))))) | |||
| (let ((company--manual-action t) | |||
| (company--manual-prefix "abc")) ;manual begin from this prefix | |||
| (should (eq t (company--good-prefix-p "!@#$"))) | |||
| (should (eq nil (company--good-prefix-p "ab"))) | |||
| (should (eq nil (company--good-prefix-p 'stop))) | |||
| (should (eq t (company--good-prefix-p '("foo" . 4)))) | |||
| (should (eq t (company--good-prefix-p "abcd"))) | |||
| (should (eq t (company--good-prefix-p "abc"))) | |||
| (should (eq t (company--good-prefix-p '("bar" . t))))))) | |||
| (ert-deftest company-multi-backend-with-lambdas () | |||
| (let ((company-backend | |||
| (list (lambda (command &optional arg &rest ignore) | |||
| (cl-case command | |||
| (prefix "z") | |||
| (candidates '("a" "b")))) | |||
| (lambda (command &optional arg &rest ignore) | |||
| (cl-case command | |||
| (prefix "z") | |||
| (candidates '("c" "d"))))))) | |||
| (should (equal (company-call-backend 'candidates "z") '("a" "b" "c" "d"))))) | |||
| (ert-deftest company-multi-backend-remembers-candidate-backend () | |||
| (let ((company-backend | |||
| (list (lambda (command &optional arg) | |||
| (cl-case command | |||
| (ignore-case nil) | |||
| (annotation "1") | |||
| (candidates '("a" "c")) | |||
| (post-completion "13"))) | |||
| (lambda (command &optional arg) | |||
| (cl-case command | |||
| (ignore-case t) | |||
| (annotation "2") | |||
| (candidates '("b" "d")) | |||
| (post-completion "42"))) | |||
| (lambda (command &optional arg) | |||
| (cl-case command | |||
| (annotation "3") | |||
| (candidates '("e")) | |||
| (post-completion "74")))))) | |||
| (let ((candidates (company-calculate-candidates nil))) | |||
| (should (equal candidates '("a" "b" "c" "d" "e"))) | |||
| (should (equal t (company-call-backend 'ignore-case))) | |||
| (should (equal "1" (company-call-backend 'annotation (nth 0 candidates)))) | |||
| (should (equal "2" (company-call-backend 'annotation (nth 1 candidates)))) | |||
| (should (equal "13" (company-call-backend 'post-completion (nth 2 candidates)))) | |||
| (should (equal "42" (company-call-backend 'post-completion (nth 3 candidates)))) | |||
| (should (equal "3" (company-call-backend 'annotation (nth 4 candidates)))) | |||
| (should (equal "74" (company-call-backend 'post-completion (nth 4 candidates))))))) | |||
| (ert-deftest company-multi-backend-handles-keyword-with () | |||
| (let ((primo (lambda (command &optional arg) | |||
| (cl-case command | |||
| (prefix "a") | |||
| (candidates '("abb" "abc" "abd"))))) | |||
| (secundo (lambda (command &optional arg) | |||
| (cl-case command | |||
| (prefix "a") | |||
| (candidates '("acc" "acd")))))) | |||
| (let ((company-backend (list 'ignore 'ignore :with secundo))) | |||
| (should (null (company-call-backend 'prefix)))) | |||
| (let ((company-backend (list 'ignore primo :with secundo))) | |||
| (should (equal "a" (company-call-backend 'prefix))) | |||
| (should (equal '("abb" "abc" "abd" "acc" "acd") | |||
| (company-call-backend 'candidates "a")))))) | |||
| (ert-deftest company-begin-backend-failure-doesnt-break-company-backends () | |||
| (with-temp-buffer | |||
| (insert "a") | |||
| (company-mode) | |||
| (should-error | |||
| (company-begin-backend (lambda (command &rest ignore)))) | |||
| (let (company-frontends | |||
| (company-backends | |||
| (list (lambda (command &optional arg) | |||
| (cl-case command | |||
| (prefix "a") | |||
| (candidates '("a" "ab" "ac"))))))) | |||
| (let (this-command) | |||
| (company-call 'complete)) | |||
| (should (eq 3 company-candidates-length))))) | |||
| (ert-deftest company-require-match-explicit () | |||
| (with-temp-buffer | |||
| (insert "ab") | |||
| (company-mode) | |||
| (let (company-frontends | |||
| (company-require-match 'company-explicit-action-p) | |||
| (company-backends | |||
| (list (lambda (command &optional arg) | |||
| (cl-case command | |||
| (prefix (buffer-substring (point-min) (point))) | |||
| (candidates '("abc" "abd"))))))) | |||
| (let (this-command) | |||
| (company-complete)) | |||
| (let ((last-command-event ?e)) | |||
| (company-call 'self-insert-command 1)) | |||
| (should (eq 2 company-candidates-length)) | |||
| (should (eq 3 (point)))))) | |||
| (ert-deftest company-dont-require-match-when-idle () | |||
| (with-temp-buffer | |||
| (insert "ab") | |||
| (company-mode) | |||
| (let (company-frontends | |||
| (company-require-match 'company-explicit-action-p) | |||
| (company-backends | |||
| (list (lambda (command &optional arg) | |||
| (cl-case command | |||
| (prefix (buffer-substring (point-min) (point))) | |||
| (candidates '("abc" "abd"))))))) | |||
| (company-idle-begin (current-buffer) (selected-window) | |||
| (buffer-chars-modified-tick) (point)) | |||
| (let ((last-command-event ?e)) | |||
| (company-call 'self-insert-command 1)) | |||
| (should (eq nil company-candidates-length)) | |||
| (should (eq 4 (point)))))) | |||
| (ert-deftest company-should-complete-whitelist () | |||
| (with-temp-buffer | |||
| (insert "ab") | |||
| (company-mode) | |||
| (let (company-frontends | |||
| company-begin-commands | |||
| (company-backends | |||
| (list (lambda (command &optional arg) | |||
| (cl-case command | |||
| (prefix (buffer-substring (point-min) (point))) | |||
| (candidates '("abc" "abd"))))))) | |||
| (let ((company-continue-commands nil)) | |||
| (let (this-command) | |||
| (company-complete)) | |||
| (company-call 'backward-delete-char 1) | |||
| (should (null company-candidates-length))) | |||
| (let ((company-continue-commands '(backward-delete-char))) | |||
| (let (this-command) | |||
| (company-complete)) | |||
| (company-call 'backward-delete-char 1) | |||
| (should (eq 2 company-candidates-length)))))) | |||
| (ert-deftest company-should-complete-blacklist () | |||
| (with-temp-buffer | |||
| (insert "ab") | |||
| (company-mode) | |||
| (let (company-frontends | |||
| company-begin-commands | |||
| (company-backends | |||
| (list (lambda (command &optional arg) | |||
| (cl-case command | |||
| (prefix (buffer-substring (point-min) (point))) | |||
| (candidates '("abc" "abd"))))))) | |||
| (let ((company-continue-commands '(not backward-delete-char))) | |||
| (let (this-command) | |||
| (company-complete)) | |||
| (company-call 'backward-delete-char 1) | |||
| (should (null company-candidates-length))) | |||
| (let ((company-continue-commands '(not backward-delete-char-untabify))) | |||
| (let (this-command) | |||
| (company-complete)) | |||
| (company-call 'backward-delete-char 1) | |||
| (should (eq 2 company-candidates-length)))))) | |||
| (ert-deftest company-auto-complete-explicit () | |||
| (with-temp-buffer | |||
| (insert "ab") | |||
| (company-mode) | |||
| (let (company-frontends | |||
| (company-auto-complete 'company-explicit-action-p) | |||
| (company-auto-complete-chars '(? )) | |||
| (company-backends | |||
| (list (lambda (command &optional arg) | |||
| (cl-case command | |||
| (prefix (buffer-substring (point-min) (point))) | |||
| (candidates '("abcd" "abef"))))))) | |||
| (let (this-command) | |||
| (company-complete)) | |||
| (let ((last-command-event ? )) | |||
| (company-call 'self-insert-command 1)) | |||
| (should (string= "abcd " (buffer-string)))))) | |||
| (ert-deftest company-no-auto-complete-when-idle () | |||
| (with-temp-buffer | |||
| (insert "ab") | |||
| (company-mode) | |||
| (let (company-frontends | |||
| (company-auto-complete 'company-explicit-action-p) | |||
| (company-auto-complete-chars '(? )) | |||
| (company-backends | |||
| (list (lambda (command &optional arg) | |||
| (cl-case command | |||
| (prefix (buffer-substring (point-min) (point))) | |||
| (candidates '("abcd" "abef"))))))) | |||
| (company-idle-begin (current-buffer) (selected-window) | |||
| (buffer-chars-modified-tick) (point)) | |||
| (let ((last-command-event ? )) | |||
| (company-call 'self-insert-command 1)) | |||
| (should (string= "ab " (buffer-string)))))) | |||
| (ert-deftest company-clears-explicit-action-when-no-matches () | |||
| (with-temp-buffer | |||
| (company-mode) | |||
| (let (company-frontends | |||
| company-backends) | |||
| (company-call 'manual-begin) ;; fails | |||
| (should (null company-candidates)) | |||
| (should (null (company-explicit-action-p)))))) | |||
| (ert-deftest company-ignore-case-replaces-prefix () | |||
| (with-temp-buffer | |||
| (company-mode) | |||
| (let (company-frontends | |||
| company-end-of-buffer-workaround | |||
| (company-backends | |||
| (list (lambda (command &optional arg) | |||
| (cl-case command | |||
| (prefix (buffer-substring (point-min) (point))) | |||
| (candidates '("abcd" "abef")) | |||
| (ignore-case t)))))) | |||
| (insert "A") | |||
| (let (this-command) | |||
| (company-complete)) | |||
| (should (string= "ab" (buffer-string))) | |||
| (delete-char -2) | |||
| (insert "A") ; hack, to keep it in one test | |||
| (company-complete-selection) | |||
| (should (string= "abcd" (buffer-string)))))) | |||
| (ert-deftest company-ignore-case-with-keep-prefix () | |||
| (with-temp-buffer | |||
| (insert "AB") | |||
| (company-mode) | |||
| (let (company-frontends | |||
| (company-backends | |||
| (list (lambda (command &optional arg) | |||
| (cl-case command | |||
| (prefix (buffer-substring (point-min) (point))) | |||
| (candidates '("abcd" "abef")) | |||
| (ignore-case 'keep-prefix)))))) | |||
| (let (this-command) | |||
| (company-complete)) | |||
| (company-complete-selection) | |||
| (should (string= "ABcd" (buffer-string)))))) | |||
| (ert-deftest company-non-prefix-completion () | |||
| (with-temp-buffer | |||
| (insert "tc") | |||
| (company-mode) | |||
| (let (company-frontends | |||
| company-end-of-buffer-workaround | |||
| (company-backends | |||
| (list (lambda (command &optional arg) | |||
| (cl-case command | |||
| (prefix (buffer-substring (point-min) (point))) | |||
| (candidates '("tea-cup" "teal-color"))))))) | |||
| (let (this-command) | |||
| (company-complete)) | |||
| (should (string= "tc" (buffer-string))) | |||
| (company-complete-selection) | |||
| (should (string= "tea-cup" (buffer-string)))))) | |||
| (ert-deftest company-pseudo-tooltip-does-not-get-displaced () | |||
| :tags '(interactive) | |||
| (with-temp-buffer | |||
| (save-window-excursion | |||
| (set-window-buffer nil (current-buffer)) | |||
| (save-excursion (insert " ff")) | |||
| (company-mode) | |||
| (let ((company-frontends '(company-pseudo-tooltip-frontend)) | |||
| (company-begin-commands '(self-insert-command)) | |||
| (company-backends | |||
| (list (lambda (c &optional arg) | |||
| (cl-case c (prefix "") (candidates '("a" "b" "c"))))))) | |||
| (let (this-command) | |||
| (company-call 'complete)) | |||
| (company-call 'open-line 1) | |||
| (should (eq 2 (overlay-start company-pseudo-tooltip-overlay))))))) | |||
| (ert-deftest company-pseudo-tooltip-show () | |||
| :tags '(interactive) | |||
| (with-temp-buffer | |||
| (save-window-excursion | |||
| (set-window-buffer nil (current-buffer)) | |||
| (insert "aaaa\n bb\nccccccc\nddd") | |||
| (search-backward "bb") | |||
| (let ((col (company--column)) | |||
| (company-candidates-length 2) | |||
| (company-candidates '("123" "45")) | |||
| (company-backend 'ignore)) | |||
| (company-pseudo-tooltip-show (company--row) col 0) | |||
| (let ((ov company-pseudo-tooltip-overlay)) | |||
| ;; With margins. | |||
| (should (eq (overlay-get ov 'company-width) 5)) | |||
| ;; FIXME: Make it 2? | |||
| (should (eq (overlay-get ov 'company-height) company-tooltip-limit)) | |||
| (should (eq (overlay-get ov 'company-column) col)) | |||
| (should (string= (overlay-get ov 'company-after) | |||
| " 123 \nc 45 c\nddd\n"))))))) | |||
| (ert-deftest company-preview-show-with-annotations () | |||
| :tags '(interactive) | |||
| (with-temp-buffer | |||
| (save-window-excursion | |||
| (set-window-buffer nil (current-buffer)) | |||
| (save-excursion (insert "\n")) | |||
| (let ((company-candidates-length 1) | |||
| (company-candidates '("123"))) | |||
| (company-preview-show-at-point (point)) | |||
| (let ((ov company-preview-overlay)) | |||
| (should (string= (overlay-get ov 'display) "123\n"))))))) | |||
| (ert-deftest company-pseudo-tooltip-show-with-annotations () | |||
| :tags '(interactive) | |||
| (with-temp-buffer | |||
| (save-window-excursion | |||
| (set-window-buffer nil (current-buffer)) | |||
| (insert " ") | |||
| (save-excursion (insert "\n")) | |||
| (let ((company-candidates-length 2) | |||
| (company-backend (lambda (action &optional arg &rest _ignore) | |||
| (when (eq action 'annotation) | |||
| (cdr (assoc arg '(("123" . "(4)"))))))) | |||
| (company-candidates '("123" "45")) | |||
| company-tooltip-align-annotations) | |||
| (company-pseudo-tooltip-show-at-point (point)) | |||
| (let ((ov company-pseudo-tooltip-overlay)) | |||
| ;; With margins. | |||
| (should (eq (overlay-get ov 'company-width) 8)) | |||
| (should (string= (overlay-get ov 'company-after) | |||
| " 123(4) \n 45 \n"))))))) | |||
| (ert-deftest company-pseudo-tooltip-show-with-annotations-right-aligned () | |||
| :tags '(interactive) | |||
| (with-temp-buffer | |||
| (save-window-excursion | |||
| (set-window-buffer nil (current-buffer)) | |||
| (insert " ") | |||
| (save-excursion (insert "\n")) | |||
| (let ((company-candidates-length 3) | |||
| (company-backend (lambda (action &optional arg &rest _ignore) | |||
| (when (eq action 'annotation) | |||
| (cdr (assoc arg '(("123" . "(4)") | |||
| ("67" . "(891011)"))))))) | |||
| (company-candidates '("123" "45" "67")) | |||
| (company-tooltip-align-annotations t)) | |||
| (company-pseudo-tooltip-show-at-point (point)) | |||
| (let ((ov company-pseudo-tooltip-overlay)) | |||
| ;; With margins. | |||
| (should (eq (overlay-get ov 'company-width) 13)) | |||
| (should (string= (overlay-get ov 'company-after) | |||
| " 123 (4) \n 45 \n 67 (891011) \n"))))))) | |||
| (ert-deftest company-create-lines-shows-numbers () | |||
| (let ((company-show-numbers t) | |||
| (company-candidates '("x" "y" "z")) | |||
| (company-candidates-length 3) | |||
| (company-backend 'ignore)) | |||
| (should (equal '(" x 1 " " y 2 " " z 3 ") | |||
| (company--create-lines 0 999))))) | |||
| (ert-deftest company-create-lines-truncates-annotations () | |||
| (let* ((ww (company--window-width)) | |||
| (data `(("1" . "(123)") | |||
| ("2" . nil) | |||
| ("3" . ,(concat "(" (make-string (- ww 2) ?4) ")")) | |||
| (,(make-string ww ?4) . "<4>"))) | |||
| (company-candidates (mapcar #'car data)) | |||
| (company-candidates-length 4) | |||
| (company-tooltip-margin 1) | |||
| (company-backend (lambda (cmd &optional arg) | |||
| (when (eq cmd 'annotation) | |||
| (cdr (assoc arg data))))) | |||
| company-tooltip-align-annotations) | |||
| (should (equal (list (format " 1(123)%s " (company-space-string (- ww 8))) | |||
| (format " 2%s " (company-space-string (- ww 3))) | |||
| (format " 3(444%s " (make-string (- ww 7) ?4)) | |||
| (format " %s " (make-string (- ww 2) ?4))) | |||
| (company--create-lines 0 999))) | |||
| (let ((company-tooltip-align-annotations t)) | |||
| (should (equal (list (format " 1%s(123) " (company-space-string (- ww 8))) | |||
| (format " 2%s " (company-space-string (- ww 3))) | |||
| (format " 3 (444%s " (make-string (- ww 8) ?4)) | |||
| (format " %s " (make-string (- ww 2) ?4))) | |||
| (company--create-lines 0 999)))))) | |||
| (ert-deftest company-column-with-composition () | |||
| (with-temp-buffer | |||
| (insert "lambda ()") | |||
| (compose-region 1 (1+ (length "lambda")) "\\") | |||
| (should (= (company--column) 4)))) | |||
| (ert-deftest company-column-with-line-prefix () | |||
| (with-temp-buffer | |||
| (insert "foo") | |||
| (put-text-property (point-min) (point) 'line-prefix " ") | |||
| (should (= (company--column) 5)))) | |||
| (ert-deftest company-column-wth-line-prefix-on-empty-line () | |||
| (with-temp-buffer | |||
| (insert "\n") | |||
| (forward-char -1) | |||
| (put-text-property (point-min) (point-max) 'line-prefix " ") | |||
| (should (= (company--column) 2)))) | |||
| (ert-deftest company-plainify () | |||
| (let ((tab-width 8)) | |||
| (should (equal-including-properties | |||
| (company-plainify "\tabc\td\t") | |||
| (concat " " | |||
| "abc " | |||
| "d ")))) | |||
| (should (equal-including-properties | |||
| (company-plainify (propertize "foobar" 'line-prefix "-*-")) | |||
| "-*-foobar"))) | |||
| (ert-deftest company-modify-line () | |||
| (let ((str "-*-foobar")) | |||
| (should (equal-including-properties | |||
| (company-modify-line str "zz" 4) | |||
| "-*-fzzbar")) | |||
| (should (equal-including-properties | |||
| (company-modify-line str "xx" 0) | |||
| "xx-foobar")) | |||
| (should (equal-including-properties | |||
| (company-modify-line str "zz" 10) | |||
| "-*-foobar zz")))) | |||
| (ert-deftest company-scrollbar-bounds () | |||
| (should (equal nil (company--scrollbar-bounds 0 3 3))) | |||
| (should (equal nil (company--scrollbar-bounds 0 4 3))) | |||
| (should (equal '(0 . 0) (company--scrollbar-bounds 0 1 2))) | |||
| (should (equal '(1 . 1) (company--scrollbar-bounds 2 2 4))) | |||
| (should (equal '(2 . 3) (company--scrollbar-bounds 7 4 12))) | |||
| (should (equal '(1 . 2) (company--scrollbar-bounds 3 4 12))) | |||
| (should (equal '(1 . 3) (company--scrollbar-bounds 4 5 11)))) | |||
| ;;; Async | |||
| (defun company-async-backend (command &optional arg) | |||
| (pcase command | |||
| (`prefix "foo") | |||
| (`candidates | |||
| (cons :async | |||
| (lambda (cb) | |||
| (run-with-timer 0.05 nil | |||
| #'funcall cb '("abc" "abd"))))))) | |||
| (ert-deftest company-call-backend-forces-sync () | |||
| (let ((company-backend 'company-async-backend) | |||
| (company-async-timeout 0.1)) | |||
| (should (equal '("abc" "abd") (company-call-backend 'candidates))))) | |||
| (ert-deftest company-call-backend-errors-on-timeout () | |||
| (with-temp-buffer | |||
| (let* ((company-backend (lambda (command &optional _arg) | |||
| (pcase command | |||
| (`candidates (cons :async 'ignore))))) | |||
| (company-async-timeout 0.1) | |||
| (err (should-error (company-call-backend 'candidates "foo")))) | |||
| (should (string-match-p "async timeout" (cadr err)))))) | |||
| (ert-deftest company-call-backend-raw-passes-return-value-verbatim () | |||
| (let ((company-backend 'company-async-backend)) | |||
| (should (equal "foo" (company-call-backend-raw 'prefix))) | |||
| (should (equal :async (car (company-call-backend-raw 'candidates "foo")))) | |||
| (should (equal 'closure (cadr (company-call-backend-raw 'candidates "foo")))))) | |||
| (ert-deftest company-manual-begin-forces-async-candidates-to-sync () | |||
| (with-temp-buffer | |||
| (company-mode) | |||
| (let (company-frontends | |||
| (company-backends (list 'company-async-backend))) | |||
| (company-manual-begin) | |||
| (should (equal "foo" company-prefix)) | |||
| (should (equal '("abc" "abd") company-candidates))))) | |||
| (ert-deftest company-idle-begin-allows-async-candidates () | |||
| (with-temp-buffer | |||
| (company-mode) | |||
| (let (company-frontends | |||
| (company-backends (list 'company-async-backend))) | |||
| (company-idle-begin (current-buffer) (selected-window) | |||
| (buffer-chars-modified-tick) (point)) | |||
| (should (null company-candidates)) | |||
| (sleep-for 0.1) | |||
| (should (equal "foo" company-prefix)) | |||
| (should (equal '("abc" "abd") company-candidates))))) | |||
| (ert-deftest company-idle-begin-cancels-async-candidates-if-buffer-changed () | |||
| (with-temp-buffer | |||
| (company-mode) | |||
| (let (company-frontends | |||
| (company-backends (list 'company-async-backend))) | |||
| (company-idle-begin (current-buffer) (selected-window) | |||
| (buffer-chars-modified-tick) (point)) | |||
| (should (null company-candidates)) | |||
| (insert "a") | |||
| (sleep-for 0.1) | |||
| (should (null company-prefix)) | |||
| (should (null company-candidates))))) | |||
| (ert-deftest company-idle-begin-async-allows-immediate-callbacks () | |||
| (with-temp-buffer | |||
| (company-mode) | |||
| (let (company-frontends | |||
| (company-backends | |||
| (list (lambda (command &optional arg) | |||
| (pcase command | |||
| (`prefix (buffer-substring (point-min) (point))) | |||
| (`candidates | |||
| (let ((c (all-completions arg '("abc" "def")))) | |||
| (cons :async | |||
| (lambda (cb) (funcall cb c))))) | |||
| (`no-cache t))))) | |||
| (company-minimum-prefix-length 0)) | |||
| (company-idle-begin (current-buffer) (selected-window) | |||
| (buffer-chars-modified-tick) (point)) | |||
| (should (equal '("abc" "def") company-candidates)) | |||
| (let ((last-command-event ?a)) | |||
| (company-call 'self-insert-command 1)) | |||
| (should (equal '("abc") company-candidates))))) | |||
| (ert-deftest company-multi-backend-forces-prefix-to-sync () | |||
| (with-temp-buffer | |||
| (let ((company-backend (list 'ignore | |||
| (lambda (command) | |||
| (should (eq command 'prefix)) | |||
| (cons :async | |||
| (lambda (cb) | |||
| (run-with-timer | |||
| 0.01 nil | |||
| (lambda () (funcall cb nil)))))) | |||
| (lambda (command) | |||
| (should (eq command 'prefix)) | |||
| "foo")))) | |||
| (should (equal "foo" (company-call-backend-raw 'prefix)))) | |||
| (let ((company-backend (list (lambda (_command) | |||
| (cons :async | |||
| (lambda (cb) | |||
| (run-with-timer | |||
| 0.01 nil | |||
| (lambda () (funcall cb "bar")))))) | |||
| (lambda (_command) | |||
| "foo")))) | |||
| (should (equal "bar" (company-call-backend-raw 'prefix)))))) | |||
| (ert-deftest company-multi-backend-merges-deferred-candidates () | |||
| (with-temp-buffer | |||
| (let* ((immediate (lambda (command &optional arg) | |||
| (pcase command | |||
| (`prefix "foo") | |||
| (`candidates | |||
| (cons :async | |||
| (lambda (cb) (funcall cb '("f")))))))) | |||
| (company-backend (list 'ignore | |||
| (lambda (command &optional arg) | |||
| (pcase command | |||
| (`prefix "foo") | |||
| (`candidates | |||
| (should (equal arg "foo")) | |||
| (cons :async | |||
| (lambda (cb) | |||
| (run-with-timer | |||
| 0.01 nil | |||
| (lambda () (funcall cb '("a" "b"))))))))) | |||
| (lambda (command &optional arg) | |||
| (pcase command | |||
| (`prefix "foo") | |||
| (`candidates '("c" "d" "e")))) | |||
| immediate))) | |||
| (should (equal :async (car (company-call-backend-raw 'candidates "foo")))) | |||
| (should (equal '("a" "b" "c" "d" "e" "f") | |||
| (company-call-backend 'candidates "foo"))) | |||
| (let ((company-backend (list immediate))) | |||
| (should (equal '("f") (company-call-backend 'candidates "foo"))))))) | |||
| ;;; Template | |||
| (ert-deftest company-template-removed-after-the-last-jump () | |||
| (with-temp-buffer | |||
| (insert "{ }") | |||
| (goto-char 2) | |||
| (let ((tpl (company-template-declare-template (point) (1- (point-max))))) | |||
| (save-excursion | |||
| (dotimes (i 2) | |||
| (insert " ") | |||
| (company-template-add-field tpl (point) "foo"))) | |||
| (company-call 'template-forward-field) | |||
| (should (= 3 (point))) | |||
| (company-call 'template-forward-field) | |||
| (should (= 7 (point))) | |||
| (company-call 'template-forward-field) | |||
| (should (= 11 (point))) | |||
| (should (zerop (length (overlay-get tpl 'company-template-fields)))) | |||
| (should (null (overlay-buffer tpl)))))) | |||
| (ert-deftest company-template-removed-after-input-and-jump () | |||
| (with-temp-buffer | |||
| (insert "{ }") | |||
| (goto-char 2) | |||
| (let ((tpl (company-template-declare-template (point) (1- (point-max))))) | |||
| (save-excursion | |||
| (insert " ") | |||
| (company-template-add-field tpl (point) "bar")) | |||
| (company-call 'template-move-to-first tpl) | |||
| (should (= 3 (point))) | |||
| (dolist (c (string-to-list "tee")) | |||
| (let ((last-command-event c)) | |||
| (company-call 'self-insert-command 1))) | |||
| (should (string= "{ tee }" (buffer-string))) | |||
| (should (overlay-buffer tpl)) | |||
| (company-call 'template-forward-field) | |||
| (should (= 7 (point))) | |||
| (should (null (overlay-buffer tpl)))))) | |||
| (defun company-call (name &rest args) | |||
| (let* ((maybe (intern (format "company-%s" name))) | |||
| (command (if (fboundp maybe) maybe name))) | |||
| (let ((this-command command)) | |||
| (run-hooks 'pre-command-hook)) | |||
| (apply command args) | |||
| (let ((this-command command)) | |||
| (run-hooks 'post-command-hook)))) | |||
| (ert-deftest company-template-c-like-templatify () | |||
| (with-temp-buffer | |||
| (let ((text "foo(int a, short b)")) | |||
| (insert text) | |||
| (company-template-c-like-templatify text) | |||
| (should (equal "foo(arg0, arg1)" (buffer-string))) | |||
| (should (looking-at "arg0")) | |||
| (should (equal "int a" | |||
| (overlay-get (company-template-field-at) 'display)))))) | |||
| (ert-deftest company-template-c-like-templatify-trims-after-closing-paren () | |||
| (with-temp-buffer | |||
| (let ((text "foo(int a, short b)!@ #1334 a")) | |||
| (insert text) | |||
| (company-template-c-like-templatify text) | |||
| (should (equal "foo(arg0, arg1)" (buffer-string))) | |||
| (should (looking-at "arg0"))))) | |||
| ;;; Clang | |||
| (ert-deftest company-clang-objc-templatify () | |||
| (with-temp-buffer | |||
| (let ((text "createBookWithTitle:andAuthor:")) | |||
| (insert text) | |||
| (company-clang-objc-templatify text) | |||
| (should (equal "createBookWithTitle:arg0 andAuthor:arg1" (buffer-string))) | |||
| (should (looking-at "arg0")) | |||
| (should (null (overlay-get (company-template-field-at) 'display)))))) | |||
| @ -0,0 +1,124 @@ | |||
| ;;; company-xcode.el --- company-mode completion back-end for Xcode projects | |||
| ;; Copyright (C) 2009-2011 Free Software Foundation, Inc. | |||
| ;; Author: Nikolaj Schumacher | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'company) | |||
| (require 'cl-lib) | |||
| (defgroup company-xcode nil | |||
| "Completion back-end for Xcode projects." | |||
| :group 'company) | |||
| (defcustom company-xcode-xcodeindex-executable (executable-find "xcodeindex") | |||
| "Location of xcodeindex executable." | |||
| :type 'file) | |||
| (defvar company-xcode-tags nil) | |||
| (defun company-xcode-reset () | |||
| "Reset the cached tags." | |||
| (interactive) | |||
| (setq company-xcode-tags nil)) | |||
| (defcustom company-xcode-types | |||
| '("Class" "Constant" "Enum" "Macro" "Modeled Class" "Structure" | |||
| "Type" "Union" "Function") | |||
| "The types of symbols offered by `company-xcode'. | |||
| No context-enabled completion is available. Types like methods will be | |||
| offered regardless of whether the class supports them. The defaults should be | |||
| valid in most contexts." | |||
| :set (lambda (variable value) | |||
| (set variable value) | |||
| (company-xcode-reset)) | |||
| :type '(set (const "Category") (const "Class") (const "Class Method") | |||
| (const "Class Variable") (const "Constant") (const "Enum") | |||
| (const "Field") (const "Instance Method") | |||
| (const "Instance Variable") (const "Macro") | |||
| (const "Modeled Class") (const "Modeled Method") | |||
| (const "Modeled Property") (const "Property") (const "Protocol") | |||
| (const "Structure") (const "Type") (const "Union") | |||
| (const "Variable") (const "Function"))) | |||
| (defvar company-xcode-project 'unknown) | |||
| (make-variable-buffer-local 'company-xcode-project) | |||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |||
| (defun company-xcode-fetch (project-bundle) | |||
| (setq project-bundle (directory-file-name project-bundle)) | |||
| (message "Retrieving dump from %s..." project-bundle) | |||
| (with-temp-buffer | |||
| (let ((default-directory (file-name-directory project-bundle))) | |||
| (call-process company-xcode-xcodeindex-executable nil (current-buffer) | |||
| nil "dump" "-project" | |||
| (file-name-nondirectory project-bundle) "-quiet") | |||
| (goto-char (point-min)) | |||
| (let ((regexp (concat "^\\([^\t\n]*\\)\t[^\t\n]*\t" | |||
| (regexp-opt company-xcode-types) | |||
| "\t[^\t\n]*\t[^\t\n]*")) | |||
| candidates) | |||
| (while (re-search-forward regexp nil t) | |||
| (add-to-list 'candidates (match-string 1))) | |||
| (message "Retrieving dump from %s...done" project-bundle) | |||
| candidates)))) | |||
| (defun company-xcode-find-project () | |||
| (let ((dir (if buffer-file-name | |||
| (file-name-directory buffer-file-name) | |||
| (expand-file-name default-directory))) | |||
| (prev-dir nil) | |||
| file) | |||
| (while (not (or file (equal dir prev-dir))) | |||
| (setq file (car (directory-files dir t ".xcodeproj\\'" t)) | |||
| prev-dir dir | |||
| dir (file-name-directory (directory-file-name dir)))) | |||
| file)) | |||
| (defun company-xcode-tags () | |||
| (when (eq company-xcode-project 'unknown) | |||
| (setq company-xcode-project (company-xcode-find-project))) | |||
| (when company-xcode-project | |||
| (cdr (or (assoc company-xcode-project company-xcode-tags) | |||
| (car (push (cons company-xcode-project | |||
| (company-xcode-fetch company-xcode-project)) | |||
| company-xcode-tags)))))) | |||
| ;;;###autoload | |||
| (defun company-xcode (command &optional arg &rest ignored) | |||
| "`company-mode' completion back-end for Xcode projects." | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-xcode)) | |||
| (prefix (and company-xcode-xcodeindex-executable | |||
| (company-xcode-tags) | |||
| (not (company-in-string-or-comment)) | |||
| (or (company-grab-symbol) 'stop))) | |||
| (candidates (let ((completion-ignore-case nil)) | |||
| (company-xcode-tags) | |||
| (all-completions arg (company-xcode-tags)))))) | |||
| (provide 'company-xcode) | |||
| ;;; company-xcode.el ends here | |||
| @ -0,0 +1,95 @@ | |||
| ;;; company-yasnippet.el --- company-mode completion back-end for Yasnippet | |||
| ;; Copyright (C) 2014 Free Software Foundation, Inc. | |||
| ;; Author: Dmitry Gutov | |||
| ;; This file is part of GNU Emacs. | |||
| ;; GNU Emacs 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. | |||
| ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |||
| ;;; Commentary: | |||
| ;; | |||
| ;;; Code: | |||
| (require 'cl-lib) | |||
| (require 'yasnippet) | |||
| (defun company-yasnippet--candidates (prefix) | |||
| (mapcan | |||
| (lambda (table) | |||
| (let ((keyhash (yas--table-hash table)) | |||
| res) | |||
| (when keyhash | |||
| (maphash | |||
| (lambda (key value) | |||
| (when (and (stringp key) | |||
| (string-prefix-p prefix key)) | |||
| (maphash | |||
| (lambda (name template) | |||
| (push | |||
| (propertize key | |||
| 'yas-annotation name | |||
| 'yas-template template) | |||
| res)) | |||
| value))) | |||
| keyhash)) | |||
| res)) | |||
| (yas--get-snippet-tables))) | |||
| ;;;###autoload | |||
| (defun company-yasnippet (command &optional arg &rest ignore) | |||
| "`company-mode' back-end for `yasnippet'. | |||
| This back-end should be used with care, because as long as there are | |||
| snippets defined for the current major mode, this back-end will always | |||
| shadow back-ends that come after it. Recommended usages: | |||
| * In a buffer-local value of `company-backends', grouped with a back-end or | |||
| several that provide actual text completions. | |||
| (add-hook 'js-mode-hook | |||
| (lambda () | |||
| (set (make-local-variable 'company-backends) | |||
| '((company-dabbrev-code company-yasnippet))))) | |||
| * After keyword `:with', grouped with other back-ends. | |||
| (push '(company-semantic :with company-yasnippet) company-backends) | |||
| * Not in `company-backends', just bound to a key. | |||
| (global-set-key (kbd \"C-c y\") 'company-yasnippet) | |||
| " | |||
| (interactive (list 'interactive)) | |||
| (cl-case command | |||
| (interactive (company-begin-backend 'company-yasnippet)) | |||
| (prefix | |||
| ;; Should probably use `yas--current-key', but that's bound to be slower. | |||
| ;; How many trigger keys start with non-symbol characters anyway? | |||
| (and yas-minor-mode | |||
| (company-grab-symbol))) | |||
| (annotation (concat " -> " (get-text-property 0 'yas-annotation arg))) | |||
| (candidates (company-yasnippet--candidates arg)) | |||
| (post-completion | |||
| (let ((template (get-text-property 0 'yas-template arg))) | |||
| (yas-expand-snippet (yas--template-content template) | |||
| (- (point) (length arg)) | |||
| (point) | |||
| (yas--template-expand-env template)))))) | |||
| (provide 'company-yasnippet) | |||
| ;;; company-yasnippet.el ends here | |||