From: Nikolaj Schumacher Date: Fri, 10 Apr 2009 08:28:03 +0000 (+0200) Subject: Added interactive form for back-ends. X-Git-Tag: 0.3~9 X-Git-Url: https://rtime.felk.cvut.cz/gitweb/sojka/company-mode.git/commitdiff_plain/715d9f8502473b20049b00554e425e844afb84ee Added interactive form for back-ends. --- diff --git a/company-css.el b/company-css.el index 6d811b7..23c2802 100644 --- a/company-css.el +++ b/company-css.el @@ -271,9 +271,12 @@ Returns \"\" if no property found, but feasible at this position." "\\_<\\([[:alpha:]-]+\\):\\(?:[^};]*[[:space:]]+\\)?\\([^};]*\\_>\\|\\)\\=" "A regular expression matching CSS tags") +;;;###autoload (defun company-css (command &optional arg &rest ignored) "A `company-mode' completion back-end for `css-mode'." + (interactive (list 'interactive)) (case command + ('interactive (company-begin-backend 'company-css)) ('prefix (and (eq major-mode 'css-mode) (or (company-grab company-css-tag-regexp 1) (company-grab company-css-pseudo-regexp 1) diff --git a/company-dabbrev.el b/company-dabbrev.el index 2a7c1b4..64e55a2 100644 --- a/company-dabbrev.el +++ b/company-dabbrev.el @@ -29,9 +29,12 @@ (dabbrev--goto-start-of-abbrev) (buffer-substring-no-properties (point) end))))) +;;;###autoload (defun company-dabbrev (command &optional arg &rest ignored) "A `company-mode' completion back-end for `dabbrev-completion'." + (interactive (list 'interactive)) (case command + ('interactive (company-begin-backend 'company-dabbrev)) ('prefix (company-grab-dabbrev-prefix)) ('candidates (let ((dabbrev-check-other-buffers)) (dabbrev--reset-global-variables) diff --git a/company-elisp.el b/company-elisp.el index 112fd11..5336d83 100644 --- a/company-elisp.el +++ b/company-elisp.el @@ -104,9 +104,12 @@ Functions are offered for completion only after ' and \(." (string-match ".*$" doc) (match-string 0 doc)))) +;;;###autoload (defun company-elisp (command &optional arg &rest ignored) "A `company-mode' completion back-end for `emacs-lisp-mode'." + (interactive (list 'interactive)) (case command + ('interactive (company-begin-backend 'company-elisp)) ('prefix (and (eq (derived-mode-p 'emacs-lisp-mode) 'emacs-lisp-mode) (company-grab-lisp-symbol))) ('candidates (company-elisp-candidates arg)) diff --git a/company-etags.el b/company-etags.el index 5f2280f..b010423 100644 --- a/company-etags.el +++ b/company-etags.el @@ -56,9 +56,12 @@ buffer automatically." (setq company-etags-buffer-table (company-etags-find-table)) company-etags-buffer-table))) +;;;###autoload (defun company-etags (command &optional arg &rest ignored) "A `company-mode' completion back-end for etags." + (interactive (list 'interactive)) (case command + ('interactive (company-begin-backend 'company-etags)) ('prefix (and (memq major-mode company-etags-modes) (not (company-in-string-or-comment)) (require 'etags nil t) diff --git a/company-files.el b/company-files.el index 4ae2d07..b81625a 100644 --- a/company-files.el +++ b/company-files.el @@ -56,9 +56,12 @@ (setq company-files-completion-cache (cons dir (nreverse candidates)))) (cdr company-files-completion-cache))) +;;;###autoload (defun company-files (command &optional arg &rest ignored) "a `company-mode' completion back-end existing file names." + (interactive (list 'interactive)) (case command + ('interactive (company-begin-backend 'company-files)) ('prefix (company-files-grab-existing-name)) ('candidates (company-files-complete arg)) ('location (cons (dired-noselect diff --git a/company-gtags.el b/company-gtags.el index d3b429a..d27d103 100644 --- a/company-gtags.el +++ b/company-gtags.el @@ -68,9 +68,12 @@ (cons (expand-file-name (match-string 2)) (string-to-number (match-string 1))))))) +;;;###autoload (defun company-gtags (command &optional arg &rest ignored) "A `company-mode' completion back-end for GNU Global." + (interactive (list 'interactive)) (case command + ('interactive (company-begin-backend 'company-gtags)) ('prefix (and (memq major-mode company-gtags-modes) (not (company-in-string-or-comment)) (company-gtags-available) diff --git a/company-ispell.el b/company-ispell.el index 0bf68c2..3096148 100644 --- a/company-ispell.el +++ b/company-ispell.el @@ -41,9 +41,12 @@ If nil, use `ispell-complete-word-dict'." (setq company-ispell-available nil)))) company-ispell-available) +;;;###autoload (defun company-ispell (command &optional arg &rest ignored) "A `company-mode' completion back-end using ispell." + (interactive (list 'interactive)) (case command + ('interactive (company-begin-backend 'company-ispell)) ('prefix (when (company-ispell-available) (company-grab "\\<\\w+\\>"))) ('candidates (lookup-words arg (or company-ispell-dictionary diff --git a/company-nxml.el b/company-nxml.el index d9d3057..2855be6 100644 --- a/company-nxml.el +++ b/company-nxml.el @@ -102,9 +102,12 @@ (all-completions arg (rng-match-possible-value-strings)))))))) +;;;###autoload (defun company-nxml (command &optional arg &rest ignored) "A `company-mode' completion back-end for `nxml-mode'." + (interactive (list 'interactive)) (case command + ('interactive (company-begin-backend 'company-nxml)) ('prefix (or (company-nxml-tag 'prefix) (company-nxml-attribute 'prefix) (company-nxml-attribute-value 'prefix))) diff --git a/company-oddmuse.el b/company-oddmuse.el index 67ab0d3..6012a1b 100644 --- a/company-oddmuse.el +++ b/company-oddmuse.el @@ -32,9 +32,12 @@ ('oddmuse-mode (with-no-warnings (oddmuse-make-completion-table oddmuse-wiki))))) +;;;###autoload (defun company-oddmuse (command &optional arg &rest ignored) "A `company-mode' completion back-end for `oddmuse-mode'." + (interactive (list 'interactive)) (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)) diff --git a/company-semantic.el b/company-semantic.el index 9a9e038..8ddcc19 100644 --- a/company-semantic.el +++ b/company-semantic.el @@ -61,9 +61,12 @@ (context (semantic-analyze-current-context))) (all-completions prefix (semantic-ia-get-completions context (point)))))) +;;;###autoload (defun company-semantic (command &optional arg &rest ignored) "A `company-mode' completion back-end using CEDET Semantic." + (interactive (list 'interactive)) (case command + ('interactive (company-begin-backend 'company-semantic)) ('prefix (and (memq major-mode '(c-mode c++-mode jde-mode java-mode)) (not (company-in-string-or-comment)) (or (company-grab company-semantic-context-regexp 2) ""))) diff --git a/company.el b/company.el index 2ebaa66..d73503b 100644 --- a/company.el +++ b/company.el @@ -65,6 +65,7 @@ ;; ;;; Change Log: ;; +;; 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. @@ -99,6 +100,7 @@ (add-to-list 'debug-ignored-errors "^No \\(document\\|loc\\)ation available$") (add-to-list 'debug-ignored-errors "^Company not ") (add-to-list 'debug-ignored-errors "^No candidate number ") +(add-to-list 'debug-ignored-errors "^Cannot complete at point$") (defgroup company nil "Extensible inline text completion mechanism" @@ -267,7 +269,8 @@ user that choice with `company-require-match'. Return value 'never overrides that option the other way around. The back-end should return nil for all commands it does not support or -does not know about." +does not know about. It should also be callable interactively and use +`company-begin-backend' to start itself in that case." :group 'company :type '(repeat (function :tag "function" nil))) @@ -407,7 +410,8 @@ Completions can be searched with `company-search-candidates' or inactive, as well. The completion data is retrieved using `company-backends' and displayed using -`company-frontends'. +`company-frontends'. If you want to start a specific back-end, call it +interactively or use `company-begin-backend'. regular keymap (`company-mode-map'): @@ -1159,6 +1163,11 @@ when the selection has been changed, the selected candidate is completed." (defun company-begin-backend (backend &optional callback) "Start a completion at point using BACKEND." + (interactive (let ((val (completing-read "Company back-end: " + obarray + 'functionp nil "company-"))) + (when val + (list (intern val))))) (when callback (setq company-callback `(lambda (completion) @@ -1167,7 +1176,9 @@ when the selection has been changed, the selected candidate is completed." (add-hook 'company-completion-cancelled-hook 'company-remove-callback nil t) (add-hook 'company-completion-finished-hook company-callback nil t)) (setq company-backend backend) - (company-manual-begin)) + ;; Return non-nil if active. + (or (company-manual-begin) + (error "Cannot complete at point"))) (defun company-begin-with (candidates &optional prefix-length require-match callback)