From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: Re: Template substitution in Emacs? Date: Mon, 10 Nov 2014 10:13:31 +0800 Message-ID: <87fvdrdcqc.fsf@ericabrahamsen.net> References: <87bnogc6ex.fsf@wmi.amu.edu.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1415585336 19991 80.91.229.3 (10 Nov 2014 02:08:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Nov 2014 02:08:56 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 10 03:08:48 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 1XnePQ-0003Km-Kf for geh-help-gnu-emacs@m.gmane.org; Mon, 10 Nov 2014 03:08:48 +0100 Original-Received: from localhost ([::1]:40614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XnePQ-0001tc-2j for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Nov 2014 21:08:48 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XneP9-0001tW-Sh for help-gnu-emacs@gnu.org; Sun, 09 Nov 2014 21:08:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XneP1-0000Rf-Cr for help-gnu-emacs@gnu.org; Sun, 09 Nov 2014 21:08:31 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:44401) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XneP1-0000RU-6A for help-gnu-emacs@gnu.org; Sun, 09 Nov 2014 21:08:23 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XneOz-0002vi-KE for help-gnu-emacs@gnu.org; Mon, 10 Nov 2014 03:08:21 +0100 Original-Received: from 222.128.162.131 ([222.128.162.131]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 10 Nov 2014 03:08:21 +0100 Original-Received: from eric by 222.128.162.131 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 10 Nov 2014 03:08:21 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 28 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 222.128.162.131 User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:2AtL1YkBBY0F2eAvaZf30BrojdU= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:100879 Archived-At: Marcin Borkowski writes: > 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? There's a package called "dollaro" on melpa that looks like it does this, though I haven't used it...