From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Pierre Lorenzon Newsgroups: gmane.emacs.help Subject: Re: Template substitution in Emacs? Date: Mon, 10 Nov 2014 05:18:33 +0100 (CET) Message-ID: <20141110.051833.1727557154251543927.devel@pollock-nageoire.net> References: <87bnogc6ex.fsf@wmi.amu.edu.pl> 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 1415593572 6065 80.91.229.3 (10 Nov 2014 04:26:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Nov 2014 04:26:12 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: mbork@wmi.amu.edu.pl Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 10 05:26:06 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 1XngYI-0005iC-4k for geh-help-gnu-emacs@m.gmane.org; Mon, 10 Nov 2014 05:26:06 +0100 Original-Received: from localhost ([::1]:40862 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XngYH-0001s1-N1 for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Nov 2014 23:26:05 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60690) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XngY1-0001rw-NC for help-gnu-emacs@gnu.org; Sun, 09 Nov 2014 23:25:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XngXv-0004jX-El for help-gnu-emacs@gnu.org; Sun, 09 Nov 2014 23:25:49 -0500 Original-Received: from smtp02.smtpout.orange.fr ([80.12.242.124]:46677 helo=smtp.smtpout.orange.fr) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XngXv-0004jN-7q for help-gnu-emacs@gnu.org; Sun, 09 Nov 2014 23:25:43 -0500 Original-Received: from localhost ([92.163.91.38]) by mwinf5d25 with ME id DgRe1p00E0pfM3Q03gRe4N; Mon, 10 Nov 2014 05:25:41 +0100 X-ME-Helo: localhost X-ME-Date: Mon, 10 Nov 2014 05:25:41 +0100 X-ME-IP: 92.163.91.38 In-Reply-To: <87bnogc6ex.fsf@wmi.amu.edu.pl> X-Mailer: Mew version 6.5 on Emacs 25.0.50 / Mule 6.0 (HANACHIRUSATO) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 80.12.242.124 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:100881 Archived-At: Hi, I think srecode is exactly what you need. First look at the info documentation and if you think that it is not enough just have a look at the cedet project and mailing list. srecode is part of cedet. Regards Pierre From: Marcin Borkowski Subject: Template substitution in Emacs? Date: Mon, 10 Nov 2014 00:15:18 +0100 > Hi there, > > assume that I want to insert an (almost) constant string in Emacs > buffer. For instance, it may be a string of the form > > "I am a {my-variable}." > > However, I want the "{my-variable}" part to be, well, variable: I want > to substitute the current value of `my-variable' for this. So that > > (setq my-variable "sentence") > (insert (template-substitute "I am a {my-variable}.")) > > would insert "I am a sentence." at point. > > Of course, I could just use (format "I am a %s." my-variable), or even > define a function to do this. The drawback would be that if the > "template" is a user-customizable thing, then the user would have to > supply %s's and not meaningful names. What's more, the /order/ of the > substituted strings would be hardcoded in the "template". > > Obviously, I could come up with such a function within 10-15 minutes or > so. But why reinvent the wheel? Is there anything like this in Emacs? > > TIA, > > -- > Marcin Borkowski > http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski > Adam Mickiewicz University >