* Template substitution in Emacs?
@ 2014-11-09 23:15 Marcin Borkowski
2014-11-10 2:13 ` Eric Abrahamsen
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Marcin Borkowski @ 2014-11-09 23:15 UTC (permalink / raw)
To: Help Gnu Emacs mailing list
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Template substitution in Emacs?
2014-11-09 23:15 Template substitution in Emacs? Marcin Borkowski
@ 2014-11-10 2:13 ` Eric Abrahamsen
2014-11-10 2:16 ` Paul W. Rankin
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Eric Abrahamsen @ 2014-11-10 2:13 UTC (permalink / raw)
To: help-gnu-emacs
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...
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Template substitution in Emacs?
2014-11-09 23:15 Template substitution in Emacs? Marcin Borkowski
2014-11-10 2:13 ` Eric Abrahamsen
@ 2014-11-10 2:16 ` Paul W. Rankin
2014-11-10 4:18 ` Pierre Lorenzon
2014-11-12 3:31 ` Robert Thorpe
3 siblings, 0 replies; 6+ messages in thread
From: Paul W. Rankin @ 2014-11-10 2:16 UTC (permalink / raw)
To: help-gnu-emacs
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?
>
> TIA,
`s-format' in the `s' package kind of does this. See discussion here:
https://github.com/magnars/s.el/issues/57
Basically...
--8<---------------cut here---------------start------------->8---
(let ((template "I am a ${my-variable}")
(my-variable "sentence"))
(s-format template
'(lambda (var)
(symbol-value (intern var)))))
=>
"I am a sentence"
--8<---------------cut here---------------end--------------->8---
--
Paul W. Rankin
http://www.paulwrankin.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Template substitution in Emacs?
2014-11-09 23:15 Template substitution in Emacs? Marcin Borkowski
2014-11-10 2:13 ` Eric Abrahamsen
2014-11-10 2:16 ` Paul W. Rankin
@ 2014-11-10 4:18 ` Pierre Lorenzon
2014-11-12 3:31 ` Robert Thorpe
3 siblings, 0 replies; 6+ messages in thread
From: Pierre Lorenzon @ 2014-11-10 4:18 UTC (permalink / raw)
To: mbork; +Cc: help-gnu-emacs
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 <mbork@wmi.amu.edu.pl>
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
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Template substitution in Emacs?
2014-11-09 23:15 Template substitution in Emacs? Marcin Borkowski
` (2 preceding siblings ...)
2014-11-10 4:18 ` Pierre Lorenzon
@ 2014-11-12 3:31 ` Robert Thorpe
2014-11-12 19:58 ` Pierre Lorenzon
3 siblings, 1 reply; 6+ messages in thread
From: Robert Thorpe @ 2014-11-12 3:31 UTC (permalink / raw)
To: Marcin Borkowski; +Cc: help-gnu-emacs
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.
As well as the things others have mentioned there's skeleton.el which is
part of Emacs.
BR,
Robert Thorpe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Template substitution in Emacs?
2014-11-12 3:31 ` Robert Thorpe
@ 2014-11-12 19:58 ` Pierre Lorenzon
0 siblings, 0 replies; 6+ messages in thread
From: Pierre Lorenzon @ 2014-11-12 19:58 UTC (permalink / raw)
To: rt; +Cc: help-gnu-emacs, mbork
From: Robert Thorpe <rt@robertthorpeconsulting.com>
Subject: Re: Template substitution in Emacs?
Date: Wed, 12 Nov 2014 03:31:30 +0000
> 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.
>
> As well as the things others have mentioned there's skeleton.el which is
If it is enough it might be good. Notice that srecode is now
part of gnu emacs. In particular srecode was intended to
extend skeleton. So if skeleton is enough stay with that but
if you want more try srecode.
Pierre
> part of Emacs.
>
> BR,
> Robert Thorpe
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-11-12 19:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-09 23:15 Template substitution in Emacs? Marcin Borkowski
2014-11-10 2:13 ` Eric Abrahamsen
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
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).