33

What's a nice way to display all snippets available to yasnippet to the current major mode?

Reactormonk
  • 21,472
  • 14
  • 74
  • 123

5 Answers5

44

this command shows the snippets and keys

 m-x yas/describe-tables
kindahero
  • 5,817
  • 3
  • 25
  • 32
16

yas/describe-tables is an alias for yas-describe-tables in yasnippet.el.

(yas/describe-tables &optional CHOOSE)

This function is obsolete since yasnippet 0.8;

use yas-describe-tables instead.

Display snippets for each table.

Sulthan Allaudeen
  • 11,330
  • 12
  • 48
  • 63
Slava Ignatyev
  • 181
  • 1
  • 4
6

Are you looking for M-x yas/insert-snippet? It will list all available snippets and you can choose one of them to insert.

Julian Qian
  • 696
  • 5
  • 8
5
(defvar lawlist-context-menu-map
  (let ((map (make-sparse-keymap "Context Menu")))
    (define-key map [help-for-help] (cons "Help" 'help-for-help))
    (define-key map [seperator-two] '(menu-item "--"))
    (define-key map [my-menu] (cons "LAWLIST" (make-sparse-keymap "My Menu")))
    (define-key map [my-menu 01] (cons "Next Line" 'next-line))
    (define-key map [my-menu 02] (cons "Previous Line" 'previous-line))
    (define-key map [seperator-one] '(menu-item "--"))
  map) "Keymap for the LAWLIST context menu.")

(defun lawlist-popup-context-menu  (event &optional prefix)
  "Popup a context menu."
  (interactive "@e \nP")
    (define-key lawlist-context-menu-map [lawlist-major-mode-menu]
      `(menu-item ,(symbol-name major-mode)
        ,(mouse-menu-major-mode-map) :visible t))
    (define-key lawlist-context-menu-map (vector major-mode)
      `(menu-item ,(concat "YAS " (symbol-name major-mode))
        ,(gethash major-mode yas--menu-table)
          :visible (yas--show-menu-p ',major-mode)))
    (popup-menu lawlist-context-menu-map event prefix))

(global-set-key [mouse-3] 'lawlist-popup-context-menu)

Example:

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
lawlist
  • 13,099
  • 3
  • 49
  • 158
2

If you are using company mode for autocompletion you can also call company-yasnippet to show all available snippets in the company interface.

Screenshot showing the available yasnippets through the company interface

fap
  • 663
  • 1
  • 5
  • 14