# Frequently Asked Questions

## Table of Contents

- Why is there an extra newline?
- Why doesn't TAB navigation work with flyspell
- How to I use alternative keys, i.e. not TAB?
- How do I turn off the minor mode where in some buffers?
- How do I define an abbrev key containing characters not supported by the filesystem?

## Why is there an extra newline?

If there is a newline at the end of a snippet definition file, YASnippet will add a newline when expanding that snippet. When editing or saving a snippet file, please be careful not to accidentally add a terminal newline.

Note that some editors will automatically add a newline for you. In Emacs, if you set `require-final-newline` to `t`, it will add the final newline automatically.

## Why doesn't TAB navigation work with flyspell

A workaround is to inhibit flyspell overlays while the snippet is active:

    (add-hook 'flyspell-incorrect-hook
    	  #'(lambda (dummy1 dummy2 dymmy3)
    	      (and yas-active-field-overlay
    		   (overlay-buffer yas-active-field-overlay))))

This is apparently related to overlay priorities. For some reason, the `keymap` property of flyspell's overlays always takes priority over the same property in YASnippet's overlays, even if one sets the latter's `priority` property to something big. If you know emacs-lisp and can solve this problem, drop a line in the discussion group.

## How to I use alternative keys, i.e. not TAB?

Edit the keymaps `yas-minor-mode-map` and `yas-keymap` as you would any other keymap:

    (define-key yas-minor-mode-map (kbd "<tab>") nil)
    (define-key yas-minor-mode-map (kbd "TAB") nil)
    (define-key yas-minor-mode-map (kbd "<the new key>") yas-maybe-expand)

    ;;keys for navigation
    (define-key yas-keymap [(tab)]       nil)
    (define-key yas-keymap (kbd "TAB")   nil)
    (define-key yas-keymap [(shift tab)] nil)
    (define-key yas-keymap [backtab]     nil)
    (define-key yas-keymap (kbd "<new-next-field-key>") 'yas-next-field-or-maybe-expand)
    (define-key yas-keymap (kbd "<new-prev-field-key>") 'yas-prev)

## How do I turn off the minor mode where in some buffers?

The best way, since version 0.6.1c, is to set the default value of the variable `yas-dont-activate` to a lambda function like so:

    (set-default 'yas-dont-activate
    	     #'(lambda ()
    		 (and yas-root-directory
    		      (null (yas-get-snippet-tables)))))

This is also the default value starting for that version. It skips the minor mode in buffers where it is not applicable (no snippet tables), but only once you have setup your yas-root-directory.

## How do I define an abbrev key containing characters not supported by the filesystem?

- Note: This question applies if you're still defining snippets whose key is the filename. This is behavior still provided by version 0.6 for backward compatibilty, but is somewhat deprecated…

For example, you want to define a snippet by the key `<` which is not a valid character for filename on Windows. This means you can't use the filename as a trigger key in this case.

You should rather use the `# key:` directive to specify the key of the defined snippet explicitly and name your snippet with an arbitrary valid filename, `lt.YASnippet` for example, using `<` for the `# key:` directive:

    # key: <
    # name: <...></...>
    # --
    <${1:div}>$0</$1>

Generated by Emacs 25.2.2 (Org mode 8.2.10) from 0.12.2 (2017-12-22 10:07:25)

Validate