Golevka / emacs-clang-complete-async

An emacs plugin to complete C and C++ code using libclang
360 stars 71 forks source link

Snippet expansion only occurs for overloaded functions. #32

Closed toojays closed 11 years ago

toojays commented 11 years ago

emacs-clang-complete-async f01488 auto-complete 1.4ish (a4f83db) yasnippet 0.8beta (20130218.2229 from MELPA)

When expanding a non-overloaded function, snippet expansion does not occur.

For example:

#include <stdio.h>

void main (void)
{
  fclos
}

with the cursor after "fclos", the completion fclose(FILE __stream) will be offered. But when pressing RET to expand, point is moved after fclose(FILE __stream), and snippet expansion does not occur.

toojays commented 11 years ago

This patch seems to fix it:

--- a/auto-complete-clang-async.el
+++ b/auto-complete-clang-async.el
@@ -270,7 +270,15 @@ This variable will typically contain include paths, e.g., (\"-I~/MyProject\" \"-
            (setq candidates (nreverse candidates))
            (setq ac-clang-template-candidates candidates)
            (setq ac-clang-template-start-point (point))
-           (ac-complete-clang-template)
+
+           (if (cdr candidates)
+               (ac-complete-clang-template)
+             ;; If there is only one candidate, auto-complete will expand it in
+             ;; ac-expand-common, and then will not perform the completion
+             ;; action, so our template will not be expanded. Work around this
+             ;; by faking completion, and going straight to the template action.
+             (progn (setq ac-last-completion (cons (point-marker) (car candidates)))
+                    (ac-clang-template-action)))

            (unless (cdr candidates) ;; unless length > 1
              (message (replace-regexp-in-string "\n" "   ;    " help))))
Golevka commented 11 years ago

I haven't seen this problem on my site (with a few tries on the latest code), maybe I need to switch to a cutting edge version of auto-complete to reproduce this problem.

toojays commented 11 years ago

Hmm, I can no longer reproduce this either, even when rolling back to the revision of emacs-clang-complete-async I mentioned when I opened the issue.

This problem must have been due to some misconfiguration on my part, which I accidentally fixed while developing this patch.

Apologies for the noise. :(