In org mode, the TAB key maps to yas-next-field-or-maybe-expand. But it is not working.

But if I run yas-expand (by hand) it works as expected.

TAB does expand in other modes.

Any ideas what might be wrong with my configuration? where to start debugging my (long) startup configuration?

thanks a lot!


I had this problem for a long time, sometimes tab worked well, sometimes it didn't. Finally, the solution for me was to.. follow advice from org-mode manual! Here, in the section about conflicts with packages, under yasnippet.el paragraph there's an explanation:

The way Org mode binds the key (binding to [tab] instead of "\t") overrules YASnippet's access to this key.

And below there are two ways to fix it, the second approach worked for me, here's the code (updated to remove deprecated stuff):

(defun yas-org-very-safe-expand ()
  (let ((yas-fallback-behavior 'return-nil)) (yas-expand)))
(add-hook 'org-mode-hook
      (lambda ()
        (add-to-list 'org-tab-first-hook 'yas-org-very-safe-expand)
        (define-key yas-keymap [tab] 'yas-next-field)))

For it to work it might be necessary to re-load org-mode, so the hook gets called.

As @npostavs suggested, it's useful to mention that this solution works for org-mode version 9.1.2 and yasnippet version 0.12.2.

  • yas-trigger-key is by now also long obsolete, and setting it won't do anything. – npostavs Oct 30 '17 at 2:22
  • @npostavs I edited the code to remove the lines about yas-trigger-key and I checked that restarting my Emacs without this code results in tabs not working, and with this code they work correctly, so it seems to do the job. does it look ok to you now? – tlegutko Oct 31 '17 at 0:37
  • 1
    It would be useful to list which org and yasnippet versions this works in. I had yasnippet working nicely with org when setting org-src-tab-acts-natively and org-src-fontify-natively, but it doesn't work with the latest 9.x org, unfortunately (ref #852). Perhaps your approach would be more robust to changes in org. – npostavs Oct 31 '17 at 2:25
  • 1
    thank you very much. It solved the problem i was having. I appreciate the time you took to write the answer. – dmg Nov 8 '17 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.