Use Popup isearch For Yasnippet Prompt

Yasnippet tries functions in yas/prompt-functions when it needs user to select one choice, such as selecting snippets with the same trigger key, such as helper method yas/choose-value.

popup is a visual popup interface library extracted from auto-complete by its author. It has better look and feel than all the built-in yas/prompt-functions. Also it is easy to customize, and its isearch mode is very efficient, the items are filtered on-the-fly when typing.

Popup snapshop

The integration is easy. Load popup.el, implement one prompt function and add it to yas/prompt-functions.

(require 'popup)
(require 'yasnippet)

;; add some shotcuts in popup menu mode
(define-key popup-menu-keymap (kbd "M-n") 'popup-next)
(define-key popup-menu-keymap (kbd "TAB") 'popup-next)
(define-key popup-menu-keymap (kbd "<tab>") 'popup-next)
(define-key popup-menu-keymap (kbd "<backtab>") 'popup-previous)
(define-key popup-menu-keymap (kbd "M-p") 'popup-previous)

(defun yas/popup-isearch-prompt (prompt choices &optional display-fn)
  (when (featurep 'popup)
      (lambda (choice)
         (or (and display-fn (funcall display-fn choice))
         :value choice))
     :prompt prompt
     ;; start isearch mode immediately
     :isearch t

(setq yas/prompt-functions '(yas/popup-isearch-prompt yas/no-prompt))
comments powered by Disqus