unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Expanding yasnippets in emacs auto-insert
@ 2014-11-18 11:14 Matthias Pfeifer
  0 siblings, 0 replies; only message in thread
From: Matthias Pfeifer @ 2014-11-18 11:14 UTC (permalink / raw)
  To: help-gnu-emacs

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>



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-18 11:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-18 11:14 Expanding yasnippets in emacs auto-insert Matthias Pfeifer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).