joaotavora / yasnippet

A template system for Emacs
http://joaotavora.github.io/yasnippet/
2.81k stars 311 forks source link

Emacs 27.2: Yasnippet To Create Source Blocks With "<s TAB" Results In "No such language mode: nil-mode" #1104

Closed RennisDitchie closed 3 years ago

RennisDitchie commented 3 years ago

Hello,

I am currently using Emacs 27.2 on Fedora Linux.

I tried to do emacs -q... but yeah, yasnippets didn't load at all so I think its because I'm using use-package in the first place for my config.

Anyway, I have placed my Yasnippet config section in my Emacs config AFTER Company Mode, which includes the following (NOTE: I use an Emacs org doc for my config).

Emacs Config (Org Doc) Section:

** 'yasnippet' to utilize snippet templates with 'M-x yas-describe-tables' (Note: Make sure your created snippets match mode's name, ex: '~/.emacs.d/snippets/python-mode')
#+BEGIN_SRC emacs-lisp
  (use-package yasnippet
    :ensure t
    :config
    (setq yas-snippet-dirs
      '("~/.emacs.d/snippets"))
    (use-package yasnippet-snippets
      :ensure t)
    (yas-reload-all))
#+END_SRC

** Add hook so that 'yasnippet' minor mode is enabled for certain modes (programming: 'C, C++, Python, JS', 'nXML', Org-Mode)
#+BEGIN_SRC emacs-lisp
  (add-hook 'c-mode-hook 'yas-minor-mode)
  (add-hook 'c++-mode-hook 'yas-minor-mode)
  (add-hook 'python-mode-hook 'yas-minor-mode)
  (add-hook 'emacs-lisp-mode-hook 'yas-minor-mode)
  (add-hook 'org-mode-hook 'yas-minor-mode)
  (add-hook 'nxml-mode-hook 'nxml-minor-mode)
#+END_SRC

Here is the affected Yasnippet that I have placed in '~/.emacs.d/snippets/org-mode/src' whose aim is to just override the default non-Caps version of the same idea:

# -*- mode: snippet -*-
# name: src
# key: <s
# --
#+BEGIN_SRC $1
  $0
#+END_SRC

Here is what I get when I attempt to do "<s TAB" in an Org Mode doc buffer within the modeline: No such language mode: nil-mode

My reasoning behind using this customized snippet is that I absolutely hate how the newer versions of Org Mode have the source blocks in non-Caps as it looks so much better in Caps, so its just a personal preference.

What's weird about this is that another similar snippet I did for bash works just fine in comparison, though obviously the user doesn't have to specify the language being used so maybe that's why, this is present in '~/.emacs.d/snippets/org-mode/bashsrc':

# -*- mode: snippet -*-
# name: bashsrc
# key: <b
# --
#+BEGIN_SRC bash
  $0
#+END_SRC

Has anyone else ran into this issue?

Thanks.

RennisDitchie commented 3 years ago

Also, this is the output of the Debugger when I hit '<s TAB':

Debugger entered--Lisp error: (error "No such language mode: nil-mode")
  signal(error ("No such language mode: nil-mode"))
  error("No such language mode: %s" nil-mode)
  org-edit-src-code()
  org-babel-do-key-sequence-in-edit-buffer("\11")
  org-indent-line()
  indent-according-to-mode()
  yas--indent-region(115547 115559 #s(yas--snippet :expand-env nil :fields (#s(yas--field :number 1 :start #<marker at 115546 in life.org> :end #<marker at 115546 in life.org> :parent-field nil :mirrors nil :transform nil :modified-p nil :next #s(yas--exit :marker #<marker at 115549 in life.org> :next nil))) :exit #s(yas--exit :marker #<marker at 115549 in life.org> :next nil) :id 3 :control-overlay nil :active-field nil :previous-active-field nil :force-exit nil))
  yas--indent(#s(yas--snippet :expand-env nil :fields (#s(yas--field :number 1 :start #<marker at 115546 in life.org> :end #<marker at 115546 in life.org> :parent-field nil :mirrors nil :transform nil :modified-p nil :next #s(yas--exit :marker #<marker at 115549 in life.org> :next nil))) :exit #s(yas--exit :marker #<marker at 115549 in life.org> :next nil) :id 3 :control-overlay nil :active-field nil :previous-active-field nil :force-exit nil))
  #f(compiled-function () #<bytecode 0xf63605>)()
  funcall(#f(compiled-function () #<bytecode 0xf63605>))
  (let nil (funcall '#f(compiled-function () #<bytecode 0xf63605>)))
  eval((let nil (funcall '#f(compiled-function () #<bytecode 0xf63605>))))
  yas--snippet-create("#+BEGIN_SRC $1\n  $0\n#+END_SRC" nil 115534 115534)
  yas-expand-snippet(#s(yas--template :key "<s" :content "#+BEGIN_SRC $1\n  $0\n#+END_SRC" :name "src" :condition nil :expand-env nil :load-file "/home/sam/.emacs.d/snippets/org-mode/src" :save-file nil :keybinding nil :uuid "src" :menu-binding-pair ((menu-item "src" (lambda nil (interactive) (yas--expand-or-visit-from-menu 'org-mode "src")) :keys "<s =>")) :group nil :perm-group nil :table #s(yas--table :name "org-mode" :hash #<hash-table equal 2/65 0x17ba06d> :uuidhash #<hash-table equal 2/65 0x138c6e1> :parents nil :direct-keymap (keymap))) 115534 115536)
  yas--expand-or-prompt-for-template((("src" . #s(yas--template :key "<s" :content "#+BEGIN_SRC $1\n  $0\n#+END_SRC" :name "src" :condition nil :expand-env nil :load-file "/home/sam/.emacs.d/snippets/org-mode/src" :save-file nil :keybinding nil :uuid "src" :menu-binding-pair ((menu-item "src" (lambda nil (interactive) (yas--expand-or-visit-from-menu ... "src")) :keys "<s =>")) :group nil :perm-group nil :table #s(yas--table :name "org-mode" :hash #<hash-table equal 2/65 0x17ba06d> :uuidhash #<hash-table equal 2/65 0x138c6e1> :parents nil :direct-keymap (keymap))))) 115534 115536)
  yas-expand()
  funcall-interactively(yas-expand)
  call-interactively(yas-expand nil nil)
  command-execute(yas-expand)

Also, I just tried this in Emacs 27.1 as well and I do not get this error in Emacs 27.1

With this in mind, it looks like an Emacs 27.2 specific issue.

RennisDitchie commented 3 years ago

Forgot to update this issue page, but this was the fix that worked for me to allow me to just use '<s' with TAB as intended to utilize the good old CAPS version of source blocks again:

(setq org-src-tab-acts-natively nil)