help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Expanding yasnippets in emacs auto-insert


From: Matthias Pfeifer
Subject: Expanding yasnippets in emacs auto-insert
Date: Tue, 18 Nov 2014 12:14:00 +0100

Hi List,

I am using emacs auto-insert to get me default file content for newly created 
files. I am planning to improve the auto-insert templates by means of 
yasnippets. (please do not propose skeletons since the skeletons language is a 
bit to crypting for my taste. Especially for longer file contents. sorry.)
I Fiddled together following defun. It operates on current buffer and searches 
all occurences of $(yas \\([a-zA-Z0-9_]+\\)). (match-string 1) is supposed to 
be the name of a yasnippet which is then expanded.

(defun mp/yas-preprocessor()
  "Replace all yasnippets in buffer. Snippets must be marked with $(yas ....)."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "$(yas \\([a-zA-Z0-9_]+\\))")
      (let ((mb (match-beginning 0))
            (ms (match-string 1))
            (me (match-end 0)))
        (goto-char (match-beginning 0))
        (delete-char 6)
        (forward-char (- me mb 6))
        (delete-char -1)
        (yas-expand)))))

Actually it already works nearly as expected - but, the snippets are not 
expanded in the "normal" way, because i am not prompted in the way it is 
defined in the snippet. eg with the following snippet

# -*- mode: snippet -*-
# contributor: Matthias
# name: defun
# key: def
# --
(defun ${1:fun} (${2:args})
 "${3:comment}"
  ${4:(interactive${5: "P"})}
  $0)

yas-expand does not prompt at fun, args or comment. In fact it just replaces 
$(yas def) by

(defun fun (args)
  "comment"
  (interactive "P")
  )

So my question is how i would be able to get a snippet expansion from my 
mp/yas-preprocessor *with* prompts?

Sincerely

Matthias Pfeifer



-- 
Matthias Pfeifer <mpfeifer77@gmail.com>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]