0
# Configuration and Initialization
1
2
Core configuration functions for setting up readline behavior, parsing initialization files, and configuring the readline environment. These functions control how readline interprets key bindings, editing modes, and other behavioral settings.
3
4
## Capabilities
5
6
### Parse and Execute Configuration Commands
7
8
Executes individual readline configuration commands, allowing runtime configuration of readline behavior without requiring configuration files.
9
10
```python { .api }
11
def parse_and_bind(string):
12
"""
13
Parse and execute single line of a readline init file.
14
15
Parameters:
16
- string (str): Configuration command to parse and execute
17
18
Returns:
19
None
20
21
Raises:
22
None - silently ignores invalid configuration strings
23
"""
24
```
25
26
**Usage Example:**
27
28
```python
29
import readline
30
31
# Enable tab completion
32
readline.parse_and_bind('tab: complete')
33
34
# Set vi editing mode
35
readline.parse_and_bind('set editing-mode vi')
36
37
# Configure key bindings
38
readline.parse_and_bind('"\C-p": previous-history')
39
readline.parse_and_bind('"\C-n": next-history')
40
41
# Set completion settings
42
readline.parse_and_bind('set completion-ignore-case on')
43
readline.parse_and_bind('set show-all-if-ambiguous on')
44
```
45
46
### Read Initialization File
47
48
Reads and parses a complete readline initialization file, processing all configuration commands contained within the file.
49
50
```python { .api }
51
def read_init_file(filename=None):
52
"""
53
Parse a readline initialization file.
54
55
Parameters:
56
- filename (str, optional): Path to initialization file to read.
57
If None, uses the default or last filename used.
58
59
Returns:
60
None
61
62
Raises:
63
IOError: If the file cannot be read or does not exist
64
"""
65
```
66
67
**Usage Example:**
68
69
```python
70
import readline
71
72
# Read default initialization file (~/.inputrc)
73
readline.read_init_file()
74
75
# Read custom initialization file
76
readline.read_init_file('/path/to/custom.inputrc')
77
78
# Read application-specific config
79
readline.read_init_file('./myapp_readline.conf')
80
```
81
82
**Common Configuration Options:**
83
84
Readline configuration supports many options that can be set via `parse_and_bind()` or initialization files:
85
86
- `set editing-mode vi` / `set editing-mode emacs` - Set editing mode
87
- `set completion-ignore-case on/off` - Case-insensitive completion
88
- `set show-all-if-ambiguous on/off` - Show all matches immediately
89
- `set visible-stats on/off` - Display file type indicators
90
- `set mark-symlinked-directories on/off` - Mark symlinked directories
91
- Key bindings using format: `"key-sequence": function-name`