YASnippet API (for auto-complete, etc) #277

Closed
zw963 opened this Issue Aug 4, 2012 · 8 comments

Projects

None yet

3 participants

@zw963
zw963 commented Aug 4, 2012

hi, It is a BIG problem for me.. because I heavy relay yasnippet, auto-complete too.

when use early version yasnippet, when time is > 0.8 second ,(setq ac-delay 0.8)

ac-complete will show a shadow auto-complete , I use this feature to complete my
dic-word and snippet.

But if open Yasnippet 0.8, auto-complete is not show shadow feature, only I use
older version or close Yasnippet completely, ac shallow feature is rework again.

@joaotavora
Owner

This is a problem with auto-complete and the fact that it uses an undocumented function (I think it is yas/all-templates) that has changed in the 0.8 alpha version you are using. 0.8 is an internal development branch that I have not published yet, but will do so soon, I hope.

You can probably get this to work if you change auto-complete to use yas--all-templates, but this may change too in the future. I will get in touch with the auto-complete author and coordinate with him.

@zw963
zw963 commented Aug 6, 2012

hi, I cannot find about yas/all-templates code in all auto-complete sources.

all about snippet code, is in auto-complete-config.el

(defface ac-yasnippet-candidate-face
  '((t (:background "sandybrown" :foreground "black")))
  "Face for yasnippet candidate."
  :group 'auto-complete)

(defface ac-yasnippet-selection-face
  '((t (:background "coral3" :foreground "white")))
  "Face for the yasnippet selected candidate."
  :group 'auto-complete)

(defun ac-yasnippet-table-hash (table)
  (cond
   ((fboundp 'yas/snippet-table-hash)
    (yas/snippet-table-hash table))
   ((fboundp 'yas/table-hash)
    (yas/table-hash table))))

(defun ac-yasnippet-table-parent (table)
  (cond
   ((fboundp 'yas/snippet-table-parent)
    (yas/snippet-table-parent table))
   ((fboundp 'yas/table-parent)
    (yas/table-parent table))))

(defun ac-yasnippet-candidate-1 (table)
  (with-no-warnings
    (let ((hashtab (ac-yasnippet-table-hash table))
          (parent (ac-yasnippet-table-parent table))
          candidates)
      (maphash (lambda (key value)
                 (push key candidates))
               hashtab)
      (setq candidates (all-completions ac-prefix (nreverse candidates)))
      (if parent
          (setq candidates
                (append candidates (ac-yasnippet-candidate-1 parent))))
      candidates)))

(defun ac-yasnippet-candidates ()
  (with-no-warnings
    (if (fboundp 'yas/get-snippet-tables)
        ;; >0.6.0
        (apply 'append (mapcar 'ac-yasnippet-candidate-1
                               (condition-case nil
                                   (yas/get-snippet-tables major-mode)
                                 (wrong-number-of-arguments
                                  (yas/get-snippet-tables)))))
      (let ((table
             (if (fboundp 'yas/snippet-table)
                 ;; <0.6.0
                 (yas/snippet-table major-mode)
               ;; 0.6.0
               (yas/current-snippet-table))))
        (if table
            (ac-yasnippet-candidate-1 table))))))

(ac-define-source yasnippet
  '((depends yasnippet)
    (candidates . ac-yasnippet-candidates)
    (action . yas/expand)
    (candidate-face . ac-yasnippet-candidate-face)
    (selection-face . ac-yasnippet-selection-face)
    (symbol . "a")))

I found yas/expand and yas/get-snippet-tables is changed since version 0.8.

@zw963
zw963 commented Aug 6, 2012

hi, I work around for remove ac-source-yasnippet from ac-source.

when auto-complete author resolve this problem, I will readd it.

@joaotavora
Owner

I've changed the title of this issue and will refer the auto-complete author here.

@lin134340

how is this problem going? i am new to emacs as well as AC and YAS, but it's so attractive for me to use AC with YAS. Just download yasnippet yesterday. Paying close attention to this.

@joaotavora joaotavora added a commit that closed this issue Aug 19, 2012
@joaotavora Closes #277: add new `yas-active-keys` (for auto-complete)
Also documented and reviewed related functionality slightly.
commit 51b182104b
8a26ab0
@joaotavora
Owner

The author of auto-complete has merged my pull request. See auto-complete/auto-complete#134. The latest versions of the two packages should be compatible.

@zw963
zw963 commented Aug 29, 2012

Thanks for you work!!

@zw963
zw963 commented Aug 29, 2012

Hi, Update to newest version , Auto complete feature still not work for me..

when use early version yasnippet, if waiting time is larger than 0.8 second ,

(setq ac-delay 0.8), ac-complete will show a shadow auto-complete tips,

I use this feature to complete my dictionary word and snippet.

But if open Yasnippet 0.8, auto-complete is not show shadow feature, only I use
older version or close Yasnippet completely, ac shallow feature is rework again.
Use the newest ac, When I setting below dictionary config:

(setq-default ac-sources '(ac-source-words-in-same-mode-buffers
                           ac-source-abbrev
                           ac-source-dictionary
                           ac-source-yasnippet  # Comment out this line, work OK.
                           ))

Open ruby mode, It still can not show the shadow tips feature..

if I comment the line, It work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment