From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: help-gnu-emacs@gnu.org
Subject: Re: Template substitution in Emacs?
Date: Mon, 10 Nov 2014 10:13:31 +0800 [thread overview]
Message-ID: <87fvdrdcqc.fsf@ericabrahamsen.net> (raw)
In-Reply-To: 87bnogc6ex.fsf@wmi.amu.edu.pl
Marcin Borkowski <mbork@wmi.amu.edu.pl> 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...
next prev parent reply other threads:[~2014-11-10 2:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-09 23:15 Template substitution in Emacs? Marcin Borkowski
2014-11-10 2:13 ` Eric Abrahamsen [this message]
2014-11-10 2:16 ` Paul W. Rankin
2014-11-10 4:18 ` Pierre Lorenzon
2014-11-12 3:31 ` Robert Thorpe
2014-11-12 19:58 ` Pierre Lorenzon
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fvdrdcqc.fsf@ericabrahamsen.net \
--to=eric@ericabrahamsen.net \
--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.
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).