Problem defining snippets
Snippets defined in .doom.d/snippets seem to work fine. However snippets defined using the yas-define-snippets function don't seem to be working properly. A minimum example file loaded from .doom.d/config.el is listed below to indicate how I am using it.
In python mode some snippets like np expands fine, but many of the other snippets defined do not expand, or trigger company completion.
In asy-mode only the snippets defined in the doom.d/snippets/asy-mode subdirectory seem to be recognized, even though a file with an asy extension opens correctly in asy-mode.
I prefer to use the yas-define-snippets function to collect together multiple snippets in one file and I have used this approach before. Would this be possible with doom-emacs? Thanks.
;;; ~/.doom.d/+yas.el -*- lexical-binding: t; -*-
(load! "lisp/asy-mode.el" )
(autoload 'asy-mode "asy-mode.el" "Asymptote major mode." t)
(add-to-list 'auto-mode-alist '("\\.asy$" . asy-mode))
(after! snippets
(yas-define-snippets
'python-mode
'(
("pd" "import pandas as pd\n$0" "pandas")
("np" "import numpy as np\n$0" "numpy")
("sp" "import scipy as sp\n$0" "scipy")))
(yas-define-snippets
'asy-mode
'(
("gm" "import geometry;\n$0" "i_geometry")
("PI" "path ${1:P} = ${2:pA}--${3:pB};\n$0" "pathI"))))
after! takes the name of a package. There is no package named snippets. If you replace it with yasnippet, then it should work.
I changed the line (after! snippets to (after! yasnippet but I still have the same issue. M-x menu-bar-open YASnippet>pyhton-mode for example seems to show only the snippets in the python-mode subdirectories of .doom.d/snippets and the doom-snippets repo.
I also had a couple of other questions:
-
Is it possible to selectively disable snippets defined in the
doom-snippetsrepo? I have a snippet with keywordfrfor\frac{$1}{$2}in LaTeX mode, butfr<TAB>shows a menu with the selection from thedoom-snippetsrepo also displayed. -
Can the precedence for
<TAB>beyas-expandthencompany-completeif no snippet expansion is found? Right now the company completion popup appears on pressing<TAB>, even if the text before corresponds to a snippet keyword, and snippet expansion is often only possible if I can press<TAB>before the company delay. If that is not possible, how should I disable company mode? I tried(remove-hook 'LaTeX-mode-hook #'company!)but that seems to work only partially.
Thanks for your help.
Can the precedence for <TAB> be yas-expand then company-complete if no snippet expansion is found?
This is already the case, unless you've disabled :config (default +bindings) or remapped TAB yourself.
Is it possible to selectively disable snippets defined in the doom-snippets repo?
This should also already be the case, unless you've disabled :editor snippets OR you've cloned doom-snippets to ~/.doom.d/snippets. Otherwise, if you have a private snippet in ~/.doom.d/snippets with the same name as a built-in snippet, yours will shadow the built-in one (it won't prompt about it, it'll just use yours, unless you have duplicates in your private snippet library).
I fixed most of the issues by disabling company-mode for tex files, as I use yasnippets and cdlatex in any case for most of the expansions, and the shadowing issue by duplicating the file from the doom repo and giving it a different trigger-key. However, snippets defined by
(after! yasnippet
(yas-define-snippets
'asy-mode
'(
("gm" "import geometry;\n$0" "i_geometry")
("PI" "path ${1:P} = ${2:pA}--${3:pB};\n$0" "pathI"))))
are not recognized in asy mode, although they are when converted to individual snippets in the doom.d/snippets/asy-mode directory. As yas-define-snippets is not widely used and probably giving rise to an obscure error, I will look into converting the snippet definitions to individual files.