Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix completion when company-mode is not available #112

Merged
merged 2 commits into from Dec 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions racer.el
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,13 @@ Commands:
:type 'boolean
:group 'racer)

(defcustom racer-complete-insert-argument-placeholders
t
"If non-nil, insert argument placeholders after completion.
Note that this feature is only available when `company-mode' is installed."
:type 'boolean
:group 'racer)

(defun racer-complete-at-point ()
"Complete the symbol at point."
(let* ((ppss (syntax-ppss))
Expand All @@ -631,14 +638,18 @@ Commands:
:company-location #'racer-complete--location
:exit-function #'racer-complete--insert-args)))))

(declare-function company-template-c-like-templatify 'company-template)

(defun racer-complete--insert-args (arg &optional _finished)
"If a ARG is the name of a completed function, try to find and insert its arguments."
(let ((matchtype (get-text-property 0 'matchtype arg)))
(if (equal matchtype "Function")
(let* ((ctx (get-text-property 0 'ctx arg))
(arguments (racer-complete--extract-args ctx)))
(insert arguments)
(company-template-c-like-templatify arguments)))))
(when (and racer-complete-insert-argument-placeholders
(require 'company-template nil t)
(equal "Function"
(get-text-property 0 'matchtype arg)))
(let* ((ctx (get-text-property 0 'ctx arg))
(arguments (racer-complete--extract-args ctx)))
(insert arguments)
(company-template-c-like-templatify arguments))))

(defun racer-complete--extract-args (str)
"Extract function arguments from STR (excluding a possible self argument)."
Expand Down