From: Matthias Pfeifer <mpfeifer77@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Expanding yasnippets in emacs auto-insert
Date: Tue, 18 Nov 2014 12:14:00 +0100 [thread overview]
Message-ID: <20141118121400.f5d47e24c768bc2213f8284c@gmail.com> (raw)
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 other threads:[~2014-11-18 11:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141118121400.f5d47e24c768bc2213f8284c@gmail.com \
--to=mpfeifer77@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.