Skip to content

Commit

Permalink
Merge pull request #112 from zhangpj/fix-capf
Browse files Browse the repository at this point in the history
Fix completion when company-mode is not available
  • Loading branch information
kngwyu authored Dec 13, 2018
2 parents bf8f76f + e4042c2 commit 7e1c016
Showing 1 changed file with 17 additions and 6 deletions.
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

0 comments on commit 7e1c016

Please sign in to comment.