1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-09 11:29:58 +00:00
TiddlyWiki5/editions/tw5.com/tiddlers/concepts/Macros.tid

43 lines
1.7 KiB
Plaintext
Raw Normal View History

2014-02-11 19:10:17 +00:00
created: 20140211171341271
2022-10-09 16:34:22 +00:00
modified: 20221009163114481
2014-09-11 14:52:47 +00:00
tags: Concepts Reference
2014-02-11 19:10:17 +00:00
title: Macros
type: text/vnd.tiddlywiki
!! Introduction
2014-02-11 19:10:17 +00:00
2022-10-07 15:56:21 +00:00
A <<.def macro>> is a named snippet of text. They are typically defined with the [[Pragma: \define]]:
2014-02-11 19:10:17 +00:00
```
\define my-macro(parameter:"Default value")
This is the macro, and the parameter is $parameter$.
\end
```
2014-09-11 14:52:47 +00:00
The name wrapped in double angled [[brackets|Brackets]] is used a shorthand way of [[transcluding|Transclusion]] the snippet. Such transclusions are known as <<.def "macro calls">>, and each call can supply a different set of parameters:
2014-09-11 14:52:47 +00:00
```
<<my-macro>>
<<my-macro "The parameter">>
```
The parameters that are specified in the macro call are substituted for special placeholders within the snippet:
* `$parameter-name$` is replaced with the value of the named parameter
* `$(variable-name)$` is replaced with the value of the named [[variable|Variables]]).
2022-10-07 15:56:21 +00:00
<<.from-version "5.3.0">> Macros have been [[superseded|Macro Pitfalls]] by [[Procedures]], [[Custom Widgets]] and [[Functions]] which together provide more robust and flexible ways to encapsulate and re-use code. It is now recommended to only use macros when textual substitution is specifically required.
!! How Macros Work
2022-10-07 15:56:21 +00:00
Macros are implemented as a special kind of [[variable|Variables]]. The only thing that distinguishes them from ordinary variables is the way that the parameters are handled.
!! Using Macros
* [[Macro Definitions]] describes how to create macros
* [[Macro Calls]] describes how to use macros
* [[Macro Parameter Handling]] describes how macro parameters work
* [[Macro Pitfalls]] describes some of the pitfalls of using macros
* [[Core Macros]] lists the built-in core macros