Skip to content

Commit 4f6e424

Browse files
committed
docs(api-and-naming): introduce infix *_mut_* for mutable varnames
1 parent bd77d1a commit 4f6e424

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

doc/api-and-naming.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
Due to its nature, bash-completion adds a number of functions and variables in
44
the shell's environment.
55

6-
| | `bash_completion` | `completions/*` |
7-
| :-------------------------------- | :------------------ | :------------------------------------------------------------------------- |
8-
| public configuration variables | `BASH_COMPLETION_*` | `BASH_COMPLETION_CMD_${Command^^}_${Config^^}` |
9-
| non-local internal variables | `_comp__*` | `_comp_cmd_${Command}__${Data}` |
10-
| exporter function local variables | `_*` (not `_comp*`) | `_*` (not `_comp*`) |
11-
| public/exported functions | `_comp_*` | `_comp_cmd_${Command}` (functions for `complete -F`) |
12-
| | | `_comp_xfunc_${Command}_${Utility}` (functions for use with `_comp_xfunc`) |
13-
| private/internal functions | `_comp__*` | `_comp_cmd_${Command}__${Utility}` (utility functions) |
6+
| | `bash_completion` | `completions/*` |
7+
|:-------------------------------------|:--------------------|:---------------------------------------------------------------------------|
8+
| public configuration variables | `BASH_COMPLETION_*` | `BASH_COMPLETION_CMD_${Command^^}_${Config^^}` |
9+
| non-local internal variables | `_comp__*` | `_comp_cmd_${Command}__${Data}` |
10+
| non-local internal mutable variables | `_comp__*_mut_*` | `_comp_cmd_${Command}__mut_${Data}` |
11+
| exporter function local variables | `_*` (not `_comp*`) | `_*` (not `_comp*`) |
12+
| public/exported functions | `_comp_*` | `_comp_cmd_${Command}` (functions for `complete -F`) |
13+
| | | `_comp_xfunc_${Command}_${Utility}` (functions for use with `_comp_xfunc`) |
14+
| private/internal functions | `_comp__*` | `_comp_cmd_${Command}__${Utility}` (utility functions) |
1415

1516
`${Command}` refers to a command name (with characters not allowed in POSIX
1617
function or variable names replaced by an underscore), `${Config}` the name of
@@ -39,6 +40,13 @@ sharing a common prefix. For example, a function named `_comp_foo` is "allowed"
3940
to access `_comp_foo__*` where `*` does not contain any double underscores,
4041
i.e. it should not access `_comp_foo__something__*` despite the common prefix.
4142

43+
Non-local internal variables are considered readonly by default. When a
44+
completion function needs to change variables for e.g. caching purposes, the
45+
variables should contain the infix `*_mut_*` anywhere in their names. This is
46+
needed to tell the test framework to allow these variables changing.
47+
Nevertheless, the completion results should be consistent among different calls
48+
and unaffected by the state of the cache variables when it is called.
49+
4250
Internal local variables of functions that "export" their results using a
4351
variable name that is passed in start with an underscore and do not start with
4452
`_comp`. The variable names that are passed in for this purpose must not start

0 commit comments

Comments
 (0)