joaotavora/yasnippet

self-defined function `expand-from-key-p`(which check current expanding come from key or binding) not work anymore after update to newest master.

Closed this issue · 3 comments

Yasnippet expanding use two form, one is from key, e.g. defTAB, another one is expand from binding, e.g. active a region, pressing some keybinding.

What i expected is, check current expanding is active by key or binding, i wrote a function, it work quite well in early version for a long time.

(defun expand-from-key-p ()
  (print (equal (this-command-keys-vector) '[tab]))
  (print (equal (this-command-keys-vector) '[TAB]))
  (equal (this-command-keys-vector) '[tab]))

But, above function not work anymore, as you can see, i print both '[TAB] and '[tab], both of them return nil.

So how to archive same effect in latest master?

Thank you.

I revert to the older version yas, it works again.

Following is the diff of my REVERT commit.

zw963/.emacs.d@e6303c1

thanks

There is usually no event which generates [TAB]. The TAB key in GUI usually generates [tab], but in a tty it generates [?\t] instead. The difference between the two is usually hidden by function-key-map which remaps [tab] to [?\t].
So the more direct fix to your code is to check something like:

(member (this-command-keys-vector) '([tab] [?\t]))

Alternatives are to check (this-single-command-raw-keys) (which is unaffected by function-key-map and hence YASnippet's code), or to switch to testing the value of this-command, or ...

It works! thank you!