joaotavora / yasnippet

A template system for Emacs
http://joaotavora.github.io/yasnippet/
2.81k stars 311 forks source link

yas-active-keys error if use binding. #315

Closed ShingoFukuyama closed 11 years ago

ShingoFukuyama commented 12 years ago

`yas-active-keys' error in version 0.8, if include binding setting like below.

# name: test
# key: test
# binding: C-c C-t
# --
text

auto-complete.el use this function as ac-source-yasnippet'. I think that remove:test #'string=' from yas-active-keys...

joaotavora commented 11 years ago

Fixed. Thanks and sorry for the delay in answering.

zw963 commented 11 years ago

Hi, Praise Jesus!! it work now.. But it still tips [yas] Error in condition evaluation: Symbol's function definition is void: nil [72 times] when a snippet is active... following is a simple example...

# -*- mode: snippet -*-
# name: reject {|e| ... }
# key: reject
# --
reject {|${1:e}| $0 }

when input rej (three char active AC), have a error tips... I think maybe my others snippet my lack of some # name:

I will feedback soon !!

zw963 commented 11 years ago

Hi, it still tips error message...

I have fix all name missing, key missing error..

I have setting

(setq yas-verbosity 1)

to suppress pop this message... when do something wrong, have this message is not bad... but I don't know how to resolve it...

joaotavora commented 11 years ago

@zw963 what is the value of of your yas-buffer-local-condition variable?

zw963 commented 11 years ago

@capitaomorte

(if
    (and
     (or
      (fourth
       (syntax-ppss))
      (fifth
       (syntax-ppss)))
     this-command
     (eq this-command 'yas-expand-from-trigger-key))
    '(require-snippet-condition . force-in-comment)
  t)
joaotavora commented 11 years ago

OK, thanks. I cannot reproduce this. Please provide a complete reproduction recipe taking out all your customizations. Just "emacs -Q"+ yasnippet + autocomplete + stepbystep description of what you do and what happens. Until you can provide such a thing, more dialog is useless.

zw963 commented 11 years ago

perpare work

cd ~/Source/Emacs git clone https://github.com/auto-complete/auto-complete git clone https://github.com/capitaomorte/yasnippet cd auto-complete git submodule init git submodule update cd ../

Please create a new lisp file: ~/Source/Emacs/1.el.

(require 'yasnippet)
(setq yas-snippet-dirs "~/Source/Emacs/yasnippet/snippets")
(yas-global-mode)

(defun expand-from-key-p ()
  "snippet expand from normal trigger key."
  (eq (symbol-function this-command) 'yas-expand-from-trigger-key))
(yas-define-condition-cache yas-expand-from-key-p (expand-from-key-p))

(require 'auto-complete-config)
(ac-config-default)
(setq-default ac-sources '(
                           ac-source-yasnippet
                           ac-source-abbrev
                           ac-source-dictionary
                           ac-source-words-in-same-mode-buffers
                           ))

Please create a snippet script. ~/Source/Emacs/yasnippet/snippets/ruby-mode/describe

# -*- mode: snippet -*-
# name: MiniTest describe
# key: describe
# condition: (yas-expand-from-key-p)
# --
describe do
  $0
end

launching emacs

emacs -Q -L yasnippet\ -L auto-complete\ -L auto-complete/lib/popup\ -L auto-complete/lib/fuzzy\

emacs-lisp setup

M-x load-file ~/Source/Emacs/1.el

what the user should do

M-x switch-to-buffer 1.rb M-x ruby-mode input inj, will show a shadow inject, TAB to expand it. reinput inj, will show a menu,

inject         a
injection     

the same times, show a error message:

[yas] Error in condition evaluation: Symbol's function definition is void: nil [7 times]

input des, no shadow be showed... show the same error message. input completely describe, will expand it.

retry des , sometimes, show menu

describe      
def             d
dee            a
det             a
deli             a
defined?     d

sometimes show menu

describe     a
def             d
dee            a
det             a
deli             a
defined?     d

sometimes show menu only one items

describe    a

error sometimes will show, sometimes no show... so faint...

resolve method

if remove describe snippet , or remove content # condition: (yas-expand-from-key-p) it worked fine.. I define this condition it in file 1.el, load it in booting.

joaotavora commented 11 years ago

thanks for the complete report. I can see the problem is in your customization:

(defun expand-from-key-p ()
  "snippet expand from normal trigger key."
  (eq (symbol-function this-command) 'yas-expand-from-trigger-key))
(yas-define-condition-cache yas-expand-from-key-p (expand-from-key-p))

this-command is nil when yas-active-keys is called from auto-complete's machinery. and that is why symbol-function errors when called with nil as an argument.

I don't know why you have it and why do you use this condition in snippets, this is not really what conditions are meant to do.

What would happen if you removed it completely?

zw963 commented 11 years ago

João Távora notifications@github.com writes:

I don't know why you have it and why do you use this condition in snippets, this is not really what conditions are meant to do.

Sorry, I review my snippets code, find it actually no need now... before now, somethimes, I hope two mild differnce snippets one must invoke use key, and another must invoke use a binding.

But now, I write key-active and binding-active snippets in one file. all condtion be eval in snippets(below # --), not need condition any more.

What would happen if you removed it completely?

I have tried, it seem just this one conditions make AC broken. it seem worked OK now.

Great!! it times to clean up my snippets. because ac, snippets will become become more easy to use, more sex to use...

And it times to say goodbye to those ugly snippets keys (what i means, is abbreviative form key, e.g. eac means => each_cons, di => delete_if. former it not easy to remember, and easy conflict each other.

I hope update all ruby-mode snippets... with some .yas-setup.el setting. if you consider.

Good luck!

zw963 commented 11 years ago

Hi, @capitaomorte , it still a irrelevant problem.

following the step before, but change 1.el with...

(require 'yasnippet)
(setq yas-snippet-dirs "~/Source/Emacs/yasnippet/snippets")
;; (yas-global-mode)
(add-hook 'ruby-mode-hook
          (lambda ()
        (yas-minor-mode 1)
            ))

(require 'auto-complete-config)
(ac-config-default)
(setq-default ac-sources '(
                           ac-source-yasnippet
                           ac-source-abbrev
                           ac-source-dictionary
                           ac-source-words-in-same-mode-buffers
                           ))

when open a ruby-mode buffer, it seem yasnippet is not started. if eval (yas-global-mode), it work OK.

joaotavora commented 11 years ago

@zw963 this last problem appears to be completely different, you are mixing up different issues. Please open a new issue and report a full detailed description like you did 4 posts ago. Auto-complete is probably not needed too.