From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Matthias Pfeifer Newsgroups: gmane.emacs.help Subject: Expanding yasnippets in emacs auto-insert Date: Tue, 18 Nov 2014 12:14:00 +0100 Message-ID: <20141118121400.f5d47e24c768bc2213f8284c@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1416309283 28343 80.91.229.3 (18 Nov 2014 11:14:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 18 Nov 2014 11:14:43 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Nov 18 12:14:36 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Xqgjy-0002U2-K0 for geh-help-gnu-emacs@m.gmane.org; Tue, 18 Nov 2014 12:14:34 +0100 Original-Received: from localhost ([::1]:52437 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xqgjx-0008TT-RM for geh-help-gnu-emacs@m.gmane.org; Tue, 18 Nov 2014 06:14:33 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xqgjd-0008SH-CV for help-gnu-emacs@gnu.org; Tue, 18 Nov 2014 06:14:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XqgjU-00006q-6t for help-gnu-emacs@gnu.org; Tue, 18 Nov 2014 06:14:13 -0500 Original-Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]:63006) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqgjU-00006Z-0K for help-gnu-emacs@gnu.org; Tue, 18 Nov 2014 06:14:04 -0500 Original-Received: by mail-wi0-f178.google.com with SMTP id hi2so3692323wib.17 for ; Tue, 18 Nov 2014 03:14:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mime-version:content-type :content-transfer-encoding; bh=85ZsVtnngGCCa7BigWyGnq5BF2UMfWDq5+yjYbat0QU=; b=RcLee2YL/hO0WdFd00/5nzqTAjevAIAtjsev9i3QMAhaGhI2Lb0iIOkoRqN3p46DEh CzcHDSrJUkWXbkK6ayRT17vI7CY9dmlGElnpgefCnrIB0uaxxVParblnPfEOZ6Fuqbqk esFTBrXFTYjYIf6FfrmNQuU8iiukzQ2UALAWjQmKy2ongi1VpyU5q+kcXvfuVKAuz7rr 76o/J/3YHCAOcXgmDBqmbpuLzCMFyNMmM6kRbBhgVYTBt90h8auzMsQ+eqoPhoAkdKKZ 98sMIsfWdr997ifFGK4SQa+goJGn0aq5SngmmFKbaNaCG4dAjwxdHFfS37vuM91uFqa6 smVg== X-Received: by 10.181.27.135 with SMTP id jg7mr38642642wid.56.1416309242740; Tue, 18 Nov 2014 03:14:02 -0800 (PST) Original-Received: from inspirion (dslb-094-220-203-041.094.220.pools.vodafone-ip.de. [94.220.203.41]) by mx.google.com with ESMTPSA id h2sm8034468wix.5.2014.11.18.03.14.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Nov 2014 03:14:02 -0800 (PST) X-Mailer: Sylpheed 3.4.0beta7 (GTK+ 2.24.23; i686-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::232 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:101026 Archived-At: 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