Skip to content

How can I add a template from a function but only for a specific mode? #136

Answered by smahm006
smahm006 asked this question in Q&A
Discussion options

You must be logged in to vote

So I tried to this with with the following code

#+begin_src emacs-lisp
  (with-eval-after-load 'tempel
    (defvar tempel-python-templates
      '((imp "import " q)
        (fimp "from " p " import " q))
      "My python templates.")

    (defun set-python-tempel-templates ()
      "Set Tempel templates for Python mode."
      (setq-local tempel-template-sources '(tempel-python-templates)))

    (add-hook 'python-ts-mode-hook 'set-python-tempel-templates))
#+end_src

But that didin't end up working.

Instead I just added my snippets and had org tangle it into the snippets directory like so:

#+begin_src lisp-data :tangle snippets/python.eld :mkdirp yes
  python-ts-mode
  (imp "import " q)
 …

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@minad
Comment options

@soil-less
Comment options

Answer selected by minad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants