Skip to content

Instantly share code, notes, and snippets.

@mooz
Created March 28, 2011 09:51
Show Gist options
  • Save mooz/890220 to your computer and use it in GitHub Desktop.
Save mooz/890220 to your computer and use it in GitHub Desktop.
(progn
;; http://d.hatena.ne.jp/kiwanami/20110224/1298526678
(defvar ac-yas-expand-autostart-backup nil "保存用")
(defun ac-yas-expand-start ()
"yasnippet展開開始時にはACを止める"
(setq ac-yas-expand-autostart-backup ac-auto-start)
(setq ac-auto-start nil))
(defun ac-yas-expand-end ()
"yasnippet展開終了時にACを再開させる"
(setq ac-auto-start ac-yas-expand-autostart-backup))
(defun ac-yas-expand-install ()
(interactive)
(add-hook 'yas/before-expand-snippet-hook 'ac-yas-expand-start)
(add-hook 'yas/after-exit-snippet-hook 'ac-yas-expand-end))
(defun ac-yas-expand-uninstall ()
(interactive)
(remove-hook 'yas/before-expand-snippet-hook 'ac-yas-expand-start)
(remove-hook 'yas/after-exit-snippet-hook 'ac-yas-expand-end))
(ac-yas-expand-install))
(defadvice ac-next (around yas-suppress-ac activate)
(if (or (eq last-command 'ac-next)
(null (car (yas/current-key))))
ad-do-it
;; close popup
(push (car (rassoc 'popup-close popup-menu-keymap))
unread-command-events)
(yas/expand)))
(progn
(defadvice yas/minor-mode (after ac-add-yas-auto activate)
(add-to-list 'ac-sources 'ac-source-yasnippet))
(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 (yas/get-snippet-tables major-mode)))
(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")))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment