Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem defining snippets #14

Open
recifx opened this issue Dec 11, 2019 · 4 comments
Open

Problem defining snippets #14

recifx opened this issue Dec 11, 2019 · 4 comments
Labels
needs-triage Issue hasn't been assessed yet

Comments

@recifx
Copy link

recifx commented Dec 11, 2019

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"))))
@hlissner
Copy link
Member

after! takes the name of a package. There is no package named snippets. If you replace it with yasnippet, then it should work.

@recifx
Copy link
Author

recifx commented Dec 12, 2019

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:

  1. Is it possible to selectively disable snippets defined in the doom-snippets repo? I have a snippet with keyword fr for \frac{$1}{$2} in LaTeX mode, but fr<TAB> shows a menu with the selection from the doom-snippets repo also displayed.

  2. Can the precedence for <TAB> be yas-expand then company-complete if 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.

@hlissner
Copy link
Member

hlissner commented Dec 12, 2019

Can the precedence for 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).

@recifx
Copy link
Author

recifx commented Dec 15, 2019

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.

@hlissner hlissner added the needs-triage Issue hasn't been assessed yet label May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Issue hasn't been assessed yet
Projects
None yet
Development

No branches or pull requests

2 participants